Ha!
I hoped you'd turn up @waaren!
The script doesn't work as intended.
The log just shows that the pianolight is turned on or off and the function isn't activated.
I scrambled something else together in 2 functions. (it's crap, I know, but it works)
Piano-on
Code: Select all
return {
active = true,
on = {
devices = {
'Piano on' ,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(domoticz, piano)
_G.logMarker = _G.moduleLabel
local light = domoticz.devices('sonof')
domoticz.log('state of ' .. piano.name .. ': ' .. piano.state .. ' => ' .. (piano.active and ' active' or 'not active') )
if piano.state == 'On' then
light.switchOn()
else
light.switchOff()
end
end
}
Piano-off
Code: Select all
return {
active = true,
on = {
devices = {
'Piano off' ,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(domoticz, piano)
_G.logMarker = _G.moduleLabel
local light = domoticz.devices('sonof')
domoticz.log('state of ' .. piano.name .. ': ' .. piano.state .. ' => ' .. (piano.active and ' active' or 'not active') )
if piano.state == 'On' then
light.switchOff()
else
light.switchOn()
end
end
}
and the log
Code: Select all
2020-07-22 00:21:57.124 Status: User: Admin initiated a switch command (460/Piano on/On)
2020-07-22 00:21:57.263 Status: dzVents: Info: Handling events for: "Piano on", value: "On"
2020-07-22 00:21:57.263 Status: dzVents: Info: ------ Start internal script: piano-aan: Device: "Piano on (RFXCOM)", Index: 460
2020-07-22 00:21:57.264 Status: dzVents: Debug: Processing device-adapter for sonof: Switch device adapter
2020-07-22 00:21:57.264 Status: dzVents: Info: state of Piano on: On => active
2020-07-22 00:21:57.265 Status: dzVents: Debug: Constructed timed-command: On
2020-07-22 00:21:57.265 Status: dzVents: Info: ------ Finished piano-aan
2020-07-22 00:21:57.265 Status: EventSystem: Script event triggered: /home/hein/domoticz/dzVents/runtime/dzVents.lua
I'd rather use your code to do the job @waaren, it's cleaner.
Bugs bug me.