Page 1 of 1

script with no status

Posted: Thursday 25 January 2024 20:45
by rfvdboom
Hallo,

I am looking for some help with the following:
I have a contact sensor that only send a "On" command. So i dont have a status to use for a event. Most of my events are in blocky.
To make an event i guess i has to be in Lua. Because i have no Status, i guess it has to be done with "lastupdate" from the device.

I tried to create something In lua/dzvents, but i simply dont understand the way of scripting. Can someine help me?
Please do not point me to the wiki page, because i have been there many times. But again, lua is abracadabra to me.

For my other contact sensor that sents On and off, i made this:

Code: Select all


t1 = os.time()
s = otherdevices_lastupdate['Raam']

year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)

commandArray = {}

t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
if (otherdevices['Raam'] == 'Open' and difference > 3600 and difference < 3660 and otherdevices_svalues['Achtertuin'] > "18" and otherdevices_svalues['Achtertuin'] > otherdevices_svalues['1ste temp'])
    or (otherdevices['Raam'] == 'Open' and difference > 3600 and difference < 3660 and otherdevices_svalues['Achtertuin'] < "5" and otherdevices_svalues['Achtertuin'] < otherdevices_svalues['1ste temp']) then
commandArray['SendNotification']='Raam open : # b #0#extradata#http'
print("Raam open")
end 
 
return commandArray

Thx

Re: script with no status

Posted: Thursday 25 January 2024 22:16
by waltervl
You have an event that the device has changed. The state is not interesting.

See below dzvents example.

Code: Select all

    return {
        on = {
            devices = {
            '<exact name of the switch>'
            }
        },
        execute = function(domoticz, item)
                domoticz.log('Hey! I am on!')
                -- do the rest of your action
        end
    }

Re: script with no status

Posted: Friday 26 January 2024 8:37
by rfvdboom
Thx Walter. It works.

Frustrating it is, that is probably that simpel :oops:

Re: script with no status

Posted: Friday 26 January 2024 13:35
by rfvdboom
OK this Lua drives me nuts. I have been struggling for a couple of hours and nothing works, beside the piece of script Walter gave me.

At the end what i want:
a notification when the windows is open after xx minutes and the tempearture is above xx degrees of below xx degrees, like the script is my first post.

I tried to make a step between, to make a dummy and switch that when to ON or OFF when the "only ON sensor" sents a signal. But even that aint working. I looked at a lot of examples in this forum, but the script wont response when the sensor is actived when is you IF THEN. I am completely lost.

I hope someone can help me of point me in the good direction.

thx again

Re: script with no status

Posted: Friday 26 January 2024 14:48
by waltervl
I personally only program in DzVents, well documented, lots of examples.

Re: script with no status

Posted: Friday 26 January 2024 15:57
by rfvdboom
thx for the reply. Well documented doesnt mean that people understand the logic of the way scripting. Domotica and IT is not my core business. Its a hobby that i tried to understand. I think i come far and learned a lot, but this DZvents (=Lua as i understand) i cant understand the logic behind it.
I spent many hours to study the wiki and examples, but :roll:. I learned myself to make scripts in bash, so its not that i doesnt try.

Only pointing to a manual isnt really helpful, because i have been there (many many times).

i hope some can help me with this.

Re: script with no status

Posted: Friday 26 January 2024 16:02
by waltervl
Why use Lua?
If I want to script something in Domoticz I google for the same function with keyword dzvents and most of the time I end up in this forum with an example script that I can modify for myself.

Edit: See for example for this issue: https://letmegooglethat.com/?q=dzvents+ ... ush+button

Re: script with no status

Posted: Friday 26 January 2024 16:45
by rfvdboom
Just to make clear, in this case is am using DZvents because you gave me the set up there.
(Only people on this forum always saying DZvents=LUA, thats why am talking about Lua)

The problem is that a lot of scipts on the forum are from people with problems. At the and they response with "i will try it" of "I fixed it", but you dont see the working script. So most of the time you work with an example and you dont know what is working and what is not working. And if you are a noob like me, its hard to understand how to get any further.

But in the meantime i finally found an example that after some modification looks like to work. Its still not best solution but the script turns on/off a Dummy. And for thát Dummy switch i use my Lua script from my first post. So the next step would be to to migrate that Lua script in de DZVents script.