Help on correcting script

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Help on correcting script

Post 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
}
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: Help on correcting script

Post by havnegata »

Noticed now that I was missing some quotation marks around the state 'On' and 'Off'.....
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Help on correcting script

Post 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
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: Help on correcting script

Post 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"
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Help on correcting script

Post 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
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Help on correcting script

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: Help on correcting script

Post by havnegata »

Thanks, but I can't find any information on the "extra" part?

Edit: Found some information here: viewtopic.php?p=140227#p140227
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Help on correcting script

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest