how to tell a script to run once? like setup() in most mcu's

Moderator: leecollings

Post Reply
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

how to tell a script to run once? like setup() in most mcu's

Post by abdolhamednik »

hello everyone ;)

how can i write a script in order to run once only? like setup() in most mcu's :?: :idea:
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by jvdz »

I am a bit puzzled about the requirement for a scheduled script which needs to run only one time ?
Can you define the condition/occasion/circumstances this script would need to run?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by abdolhamednik »

jvdz wrote: Wednesday 21 October 2020 11:36 I am a bit puzzled about the requirement for a scheduled script which needs to run only one time ?
Can you define the condition/occasion/circumstances this script would need to run?

Jos
exactly like mcu's where there is a setup() which runs to do some settings only once
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by jvdz »

I had seen that bit, but that doesn't explain the purpose in domoticz yet for me.
So you want to run a script at the start of the domoticz service and run it one time?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by abdolhamednik »

jvdz wrote: Wednesday 21 October 2020 12:25 I had seen that bit, but that doesn't explain the purpose in domoticz yet for me.
So you want to run a script at the start of the domoticz service and run it one time?

Jos
yeah
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by waaren »

abdolhamednik wrote: Wednesday 21 October 2020 13:35 yeah
You might want to look at dzVents system event Start
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by jvdz »

The easiest way I would do it is to shell a script from the domoticz.sh script started by the service to do the required tasks. probably add a sleep in there for a couple of seconds to give Domoticz time to startup and then perform the tasks required.
Still not sure what it is you need to do a startup so am just thinking out loud here.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by abdolhamednik »

jvdz wrote: Wednesday 21 October 2020 13:42 The easiest way I would do it is to shell a script from the domoticz.sh script started by the service to do the required tasks. probably add a sleep in there for a couple of seconds to give Domoticz time to startup and then perform the tasks required.
Still not sure what it is you need to do a startup so am just thinking out loud here.

Jos
maybe it is required to shut a window at first to let the system know what the window state is
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by jvdz »

abdolhamednik wrote: Wednesday 21 October 2020 14:34
jvdz wrote: Wednesday 21 October 2020 13:42 The easiest way I would do it is to shell a script from the domoticz.sh script started by the service to do the required tasks. probably add a sleep in there for a couple of seconds to give Domoticz time to startup and then perform the tasks required.
Still not sure what it is you need to do a startup so am just thinking out loud here.

Jos
maybe it is required to shut a window at first to let the system know what the window state is
Not sure how your reply is an answer to my post. :?
It shouldn't be that hard to define what it is you want to accomplish at startup of Domoticz.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by abdolhamednik »

I would be thankful to know how :) "to shut a window whenever the system starts, i.e. a power loss and return"
you know, i don't have a sensor on the window to know its status. so i guess shutting first is the only way to make sure about it
Last edited by abdolhamednik on Thursday 22 October 2020 7:18, edited 1 time in total.
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by abdolhamednik »

waaren wrote: Wednesday 21 October 2020 13:39
abdolhamednik wrote: Wednesday 21 October 2020 13:35 yeah
You might want to look at dzVents system event Start
thanks waaren. i'm reading that... :geek:
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by abdolhamednik »

waaren wrote: Wednesday 21 October 2020 13:39
abdolhamednik wrote: Wednesday 21 October 2020 13:35 yeah
You might want to look at dzVents system event Start
i followed it and wrote this short script, test, but it was not successful...

Code: Select all

return {
        on = {
          devices = {
             '<exact name of the switch>'
          }
        },
        execute = function(domoticz, switch)
          if (switch.state == 'On') then
             domoticz.log('Hey! I am on!')
          else
             domoticz.log('Hey! I am off!')
          end
        end
    }
of course i made these settings:
Using dzVents with Domoticz

In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the check-box ‘dzVents disabled’ is not checked. Also make sure that in the Security section in the settings (Setup > Settings > System > Local Networks (no username/password) you allow 127.0.0.1 (and / or ::1 when using IPv6 ) to not need a password. dzVents does use this port to get the location settings and to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by waaren »

abdolhamednik wrote: Thursday 22 October 2020 7:52 i followed it and wrote this short script, test, but it was not successful...
Can you define not successful.. ?

Did you replace <exact name of the switch > with the name of your switch ?
What did you expect and hat happened. What is in the log?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by abdolhamednik »

waaren wrote: Thursday 22 October 2020 7:56
abdolhamednik wrote: Thursday 22 October 2020 7:52 i followed it and wrote this short script, test, but it was not successful...
Can you define not successful.. ?

Did you replace <exact name of the switch > with the name of your switch ?
What did you expect and hat happened. What is in the log?
Yes, Of course. The switch is: R1(1.52)<8-3>[3]*

when i switched on and off that in the switches tab of domoticz, i hoped to see: "Hi! i am on or off" in the log. but saw only " ... admin switched on R1(1.52)<8-3>[3]* ... " or sth like that
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by waaren »

abdolhamednik wrote: Thursday 22 October 2020 8:12 when i switched on and off that in the switches tab of domoticz, i hoped to see: "Hi! i am on or off" in the log. but saw only " ... admin switched on R1(1.52)<8-3>[3]* ... " or sth like that
When I use that name in the script and save it as dzVents, I see

Code: Select all

2020-10-22 08:34:38.683 Status: User: Admin initiated a switch command (672/R1(1.52)<8-3>[3]*/On)
2020-10-22 08:34:38.911 Status: dzVents: Info: Handling events for: "R1(1.52)<8-3>[3]*", value: "On"
2020-10-22 08:34:38.911 Status: dzVents: Info: ------ Start internal script: Script #6: Device: "R1(1.52)<8-3>[3]* (Virtual)", Index: 672
2020-10-22 08:34:38.913 Status: dzVents: Info: Hey! I am on!
2020-10-22 08:34:38.914 Status: dzVents: Info: ------ Finished Script #6
Can you have a look in [Setup][Settings] [Other] and check that both dzVents and EventSystem are set as enabled and loglevel to "Errors + minimal execution info" ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by abdolhamednik »

you are right! i think there is a problem with my device which the manufacturer has installed domoticz on, he has renamed it as Avisa... :!:
Here is what my log is:

2020-10-22 11:04:44.345 (hsb) Light/Switch (R1(1.52)<8-3>[3]*)
2020-10-22 11:04:44.304 Status: User: Admin initiated a switch command (3/R1(1.52)<8-3>[3]*/Off)
.
.
.
2020-10-22 11:04:44.594 Error: EventSystem: in /home/pi/avisa/dzVents/runtime/dzVents.lua: /home/pi/avisa/dzVents/runtime/Avisa.lua:39: attempt to perform arithmetic on field 'sunsetInMinutes' (a nil value)
.
.
.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: how to tell a script to run once? like setup() in most mcu's

Post by waaren »

abdolhamednik wrote: Thursday 22 October 2020 9:39 2020-10-22 11:04:44.594 Error: EventSystem: in /home/pi/avisa/dzVents/runtime/dzVents.lua: /home/pi/avisa/dzVents/runtime/Avisa.lua:39: attempt to perform arithmetic on field 'sunsetInMinutes' (a nil value)
Did you set your location details in [Setup][Settings][Systems] ? If not domoticz / dzVents cannot determine the local time and everything derived from it.
Also kind of hard to help you if someone renamed system files in the dzVents runtime folder (and maybe on other places ?)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest