ENP-KIT-RL1
rl
library implements relay management for the ENP-KIT-RL1.
rl.is_closed
-- @return boolean Relay status
function rl.is_closed()
end
Returns the current state of a relay:
true
- relay is closedfalse
- relay is opened
Example
status = rl.is_closed()
if status then
enapter.log("Relay is closed")
else
enapter.log("Relay is openned")
end
rl.open
function rl.open()
end
Opens relay contact.
rl.close
function rl.close()
end
Closes relay contact.
rl.impulse
-- @param duration - impulse duration, in milliseconds
-- @note this command will only close and then open relay. It has no effect if relay is already closed.
function rl.impulse(duration)
end
Blueprint Example
- manifest.yml
- Lua
blueprint_spec: "device/1.0"
display_name: My Device Switch
description: Automatic device switch
icon: enapter-home
telemetry:
status:
display_name: Bar status
type: string
enum:
- light
- dark
communication_modules:
rl1:
product: ENP-RL1
lua_file: firmware.lua
commands:
home_light_switch_on:
display_name: Ligh On
group: light
ui:
icon: white-balance-sunny
quick_access: true
home_light_switch_off:
display_name: Ligh Off
group: light
ui:
icon: moon-waning-crescent
quick_access: true
command_groups:
light:
display_name: Ligh
-- To send data to Enapter Cloud use `enapter` variable as shown below.
function send_properties()
enapter.send_properties({ vendor = "Enapter", model = "ENP-RL1" })
end
function send_telemetry()
local telemetry = {}
local connected = rl.is_closed()
telemetry["connected"] = connected
if connected then
telemetry["status"] = "light"
else
telemetry["status"] = "dark"
end
enapter.send_telemetry(telemetry)
end
function light_on(ctx, args)
rl.open()
end
function light_off(ctx, args)
rl.close()
end
-- Register periodic function, will send properties every 30 seconds
scheduler.add(30000, send_properties)
-- Register periodic function, will send telemetry every 1 second
scheduler.add(1000, send_telemetry)
enapter.register_command_handler("home_light_switch_on", light_on)
enapter.register_command_handler("home_light_switch_off", light_off)