ÿþ--======================================================================================= -- Monitoring Program for Echoflex Controllers ERM and ERDRC controllers, supported on -- the CAN2GO gateway. -- Echoflex Solutions, Inc. -- Date: April 2011 -- Author: Ted Prime -- Description: This program monitors controllers and exposes the data contained within -- the status telegram as BACnet variables. The status message feature of the controller -- must be enabled, see the controller installation guide for information on this -- message. -- The program assumes that there are two (2) EnOcean Relay objects and one (1) EnOcean -- switch objects defined in the Can2Go Controller environment. One relay is associated -- with the ERM relay and the other to the ERDRC relay. The switch is not linked to -- either controller. -- The program will have the ERM relay operate according to the switch state. This can -- be changed to have some other variable activate the ERM relay. -- Copy and paste this program into a blank LUA prgramming environment. -- -- This program is provided free of charge and is intended only to demonstrate integration -- between the Can2Go gateway and Echoflex lighting controllers. Echoflex assumes no -- responsibility for this program and cannot be held liable for any damages incurred -- through it's use. --========================================================================================== -- Initilize the variables if monitor == nil then monitor = true -- *** Variables and Functions *** -- Map this programs variables to BACnet points (analog values) -- The AV and BV variables must be defined on the Can2Go controller first. Change the program's variables -- to correspond with the variables name. var("ERM_Relay", "ME.BO23") -- First EnOcean Relay var("ERM_State", "ME.BO43") var("ERDRC_Relay", "ME.BO24") -- Second EnOcean Relay var("ERDRC_State", "ME.BO44") var("ERM_Switch", "ME.BI21") -- First EnOcean Switch ERM_Light_level = ME.AV1_Present_Value -- requires a light sensor linked to the controller ERM_Light_Setpoint = ME.AV2_Present_Value ERM_Relay_State = ME.BV3_Present_Value ERM_Repeater_State = ME.BV1_Present_Value ERM_Occupancy_State = ME.BV2_Present_Value -- requires a motion sensor linked to the controller ERDRC_Light_level = ME.AV3_Present_Value -- requires a light sensor linked to the controller ERDRC_Light_Setpoint = ME.AV4_Present_Value Dimming_Output = ME.AV5_Present_Value ERDRC_Relay_State = ME.BV6_Present_Value ERDRC_Repeater_State = ME.BV4_Present_Value ERDRC_Occupancy_State = ME.BV5_Present_Value-- requires a motion sensor linked to the controller -- *** Radio ID's *** -- Radio ID's are acquired from the device by enabling the status message erm_id = 0x010001E4 erdrc_id = 0xFFF8002B packets_loop = 10 -- Maximum number of packets processed in one pass. script_debug = ON -- ON: Debugs activated, OFF: Debugs deactivated. end ---------------------------------------------------------------------------- -- Debug print utility function. ---------------------------------------------------------------------------- print_debug = function(...) if script_debug == ON then print(string.sub(os.date(), 10, 17), ...) end end ---------------------------------------------------------------------------- -- Process a telegram --------------------------------------------------------------------------- eo_process = function(eo_packet) if eo_packet.enocean_id == erm_id then -- do stuff print ("ERM Illumination is ", (eo_packet.bytes[9]*2), "lux") ERM_Light_level.value = eo_packet.bytes[9]*2 print ("ERM Illumination Set point is ",(eo_packet.bytes[8]*2), "lux") ERM_Light_Setpoint.value = eo_packet.bytes[8]*2 if bit.band(eo_packet.bytes[6], 0x01) == 0x01 then ERM_Relay_State.value = 1 else ERM_Relay_State.value = 0 end if bit.band(eo_packet.bytes[6], 0x02) == 0x02 then ERM_Occupancy_State.value = 1 else ERM_Occupancy_State.value = 0 end if bit.band(eo_packet.bytes[6], 0x80) == 0x80 then ERM_Repeater_State.value = 1 else ERM_Repeater_State.value = 0 end elseif eo_packet.enocean_id == erdrc_id then -- do more stuff print ("ERDRC Illumination is ", (eo_packet.bytes[9]*2), "lux") ERDRC_Light_level.value = eo_packet.bytes[9]*2 print ("ERDRC Illumination Set point is ",(eo_packet.bytes[8]*2), "lux") ERDRC_Light_Setpoint.value = eo_packet.bytes[8]*2 print ("Dimming output is ", eo_packet.bytes[7]*0.39, "%") Dimming_Output = eo_packet.bytes[7]*0.39 if bit.band(eo_packet.bytes[6], 0x01) == 0x01 then ERDRC_Relay_State.value = 1 else ERDRC_Relay_State.value = 0 end if bit.band(eo_packet.bytes[6], 0x02) == 0x02 then ERDRC_Occupancy_State.value = 1 else ERDRC_Occupancy_State.value = 0 end if bit.band(eo_packet.bytes[6], 0x80) == 0x80 then ERDRC_Repeater_State.value = 1 else ERDRC_Repeater_State.value = 0 end end end -- ** Main Program Loop ** -- --------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Packet processing loop: -- This is where we check for incoming packets and dispatch them. -- The program timer is set to 5 seconds. ---------------------------------------------------------------------------- local packets_done = 0 while packets_done < packets_loop do eo_packet = vm.eo_read(-1) -- Remove oldest packet from RX queue if eo_packet then -- A valid packet was received: eo_process(eo_packet) -- Process the packet packets_done = packets_done + 1 else -- No valid packet was present: break -- No more packet to process end ERM_State = 1 ERM_Relay = ERM_Switch -- may pause up to 5 seconds before acting end -- END OF SCRIPT