Help sensor motion 10 mins ago  [Solved]

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

Moderator: leecollings

Post Reply
Hydci
Posts: 35
Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Help sensor motion 10 mins ago

Post by Hydci »

Hello,
I wrote this automation in Dzvent I would like a helping hand because I think I was wrong I would like the notification of my motion sensor to be sent only when the previous ON state was 10 mins ago

Code: Select all

return {

    on = { devices = { ["Capteur BAT"] = {'at 8:00-20:00'} }
       },
   
       execute = function(domoticz, item )
        if item.state == "On" and domoticz.devices("Capteur BAT").lastUpdate.minutesAgo >10 then
            os.execute("curl -u XXXXX:XXXXX -s -o /dev/null 2>&1 'http://XXXXXX:7080/send.html?smsto=XXXXXXXXX&smsbody=Courier+dans+la+bo%C3%AEte+au+lettre&smstype=sms'")
        end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help sensor motion 10 mins ago

Post by waaren »

Hydci wrote: Saturday 21 November 2020 8:58 I wrote this automation in Dzvent I would like a helping hand because I think I was wrong I would like the notification of my motion sensor to be sent only when the previous ON state was 10 mins ago.
I don't know about the curl but the rest of the script seem to be OK.
You could check the logic with

Code: Select all

return 
{
    on = 
    { 
        devices = 
        {
            ["Capteur BAT"] = {'at 8:00-20:00'}, 
        },
    },
   
   logging = 
   {
        level = domoticz.LOG_DEBUG,
        marker = 'lastUpdate Capteur BAT', 
   },
   
    execute = function(dz, item )
        if item.state == "On" and item.lastUpdate.secondsAgo > 20 then
            dz.log(item.name .. '.lastUpdate.secondsAgo = ' .. item.lastUpdate.secondsAgo .. ' seconds (> 20)',dz.LOG_DEBUG)
        elseif item.state == "On"  then
            dz.log(item.name .. '.lastUpdate.secondsAgo = ' .. item.lastUpdate.secondsAgo .. ' seconds (=< 20)' ,dz.LOG_DEBUG)
        else
            dz.log('State of ' .. item.name .. ' is ' .. item.state,dz.LOG_DEBUG)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Hydci
Posts: 35
Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Help sensor motion 10 mins ago

Post by Hydci »

Hello @waaren
I haven't seen your answer before thank you that helped me get it working however I got an error adding a second sensor syntax error I don't think I'm wrong though

Code: Select all

     on = 
    { 
        devices = 
        {
            ["Capteur BAT", "Capteur Porte" ] = {'at 8:00-20:00'}, 
        },
    },
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help sensor motion 10 mins ago  [Solved]

Post by waaren »

Hydci wrote: Wednesday 25 November 2020 15:14 I haven't seen your answer before thank you that helped me get it working however I got an error adding a second sensor syntax error I don't think I'm wrong though
I would not go as far to say it's wrong. Let's agree it's almost right..
Please try with:

Code: Select all

     on = 
    { 
        devices = 
        {
            ["Capteur BAT"] = {'at 8:00-20:00'}, 
            ["Capteur Porte" ] = {'at 8:00-20:00'}, 
        },
    },
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Hydci
Posts: 35
Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Help sensor motion 10 mins ago

Post by Hydci »

Hello, I confirm the syntax and the correct thanks for the help my script and add-in solved thank you
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest