Page 1 of 1

Help on correcting script

Posted: Friday 01 December 2017 13:39
by havnegata
This is my first effort on making a DzVents script. Actually I'm just converting my blockly. Anyway, I'm trying to make a "SomeoneHome" switch turn on when there is motion or the TV is on. It kind of works, but only on the device "StueNord_bevegelse" and not the TV or the other motion detector.

Code: Select all

return {
    on = {
        devices = {'StueNord_bevegelse', 'StueSoer_bevegelse', 'LGTV', 'SomeoneHome', 'x_minute_timer'}
            },
    execute = function(domoticz, device)
        if (device.name == 'StueNord_bevegelse' and device.state == 'Motion' or
            device.name == 'StueSoer_bevegelse' and device.state == On or
            device.name == 'LGTV' and device.state == On and
            device.name == 'SomeoneHome' and device.state == Off and
            device.name == 'x_minute_timer' and device.state == Off) then
            domoticz.devices('SomeoneHome').switchOn()
            domoticz.devices('x_minute_timer').switchOn()
            domoticz.notify('Noen er hjemme!', dz.PRIORITY_LOW)
                            
        end
    end
}

Re: Help on correcting script

Posted: Friday 01 December 2017 13:49
by havnegata
Noticed now that I was missing some quotation marks around the state 'On' and 'Off'.....

Re: Help on correcting script

Posted: Friday 01 December 2017 13:55
by jvdz
I've tried to interpret what you wanted from the statements and guess this should be making more sense I hope:

Code: Select all

return {
    on = {
        devices = {'StueNord_bevegelse', 'StueSoer_bevegelse', 'LGTV', 'SomeoneHome', 'x_minute_timer'}
            },
    execute = function(domoticz, device)
        if ((device.name == 'StueNord_bevegelse' and (device.state == 'Motion' or device.state == "On")) 
        or  (device.name == 'LGTV' and device.state == "On")
        or  (device.name == 'SomeoneHome' and device.state == "Off")
        or  (device.name == 'x_minute_timer' and device.state == "Off") then
            domoticz.devices('SomeoneHome').switchOn()
            domoticz.devices('x_minute_timer').switchOn()
            domoticz.notify('Noen er hjemme!', dz.PRIORITY_LOW)
                            
        end
    end
}
Jos

Re: Help on correcting script

Posted: Friday 01 December 2017 14:20
by havnegata
Thanks, got it working!! Maybe you can help me on another thing. The last sentence is a notification on Pushover. "domoticz.PRIORITY_MODERATE" is not working as I was hoping. I was hoping to get a silent notification with vibration, but it comes with sound. "domoticz.PRIORITY_LOW" also comes with sound. I have also tried "domoticz.PRIORITY_LOW, domoticz.SOUND_NONE, domoticz.NSS_PUSHOVER"

Re: Help on correcting script

Posted: Friday 01 December 2017 14:28
by jvdz
I am sorry, but I have zero DzVents experience and still prefer the old fashioned LUA coding... habit of an "old fart" :-)

Jos

Re: Help on correcting script

Posted: Friday 01 December 2017 19:58
by dannybloe
You have to take a good look at the notify method as it takes several arguments:
notify(subject, message, priority, sound, extra, subsystem)

So priority is the third argument. In your code it is the second which is the actual message.

Re: Help on correcting script

Posted: Friday 01 December 2017 21:39
by havnegata
Thanks, but I can't find any information on the "extra" part?

Edit: Found some information here: viewtopic.php?p=140227#p140227

Re: Help on correcting script

Posted: Sunday 03 December 2017 11:47
by dannybloe
Indeed.. the extraData part is poorly documentation (I had to dive into the C++ code) and it seems that it is only relevant for pushover notifications.