how to tell a script to run once? like setup() in most mcu's
Moderator: leecollings
- 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
hello everyone
how can i write a script in order to run once only? like setup() in most mcu's
how can i write a script in order to run once only? like setup() in most mcu's
- 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
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
Can you define the condition/occasion/circumstances this script would need to run?
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
- 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
exactly like mcu's where there is a setup() which runs to do some settings only once
- 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
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
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
- abdolhamednik
- Posts: 39
- Joined: Sunday 27 September 2020 7:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Contact:
- 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
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
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- 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
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
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
- 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
maybe it is required to shut a window at first to let the system know what the window state isjvdz 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
- 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
Not sure how your reply is an answer to my post.abdolhamednik wrote: ↑Wednesday 21 October 2020 14:34maybe it is required to shut a window at first to let the system know what the window state isjvdz 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
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
- 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
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
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.
- 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
thanks waaren. i'm reading that...
- 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
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
}
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.
- 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
Can you define not successful.. ?abdolhamednik wrote: ↑Thursday 22 October 2020 7:52 i followed it and wrote this short script, test, but it was 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
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- 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
Yes, Of course. The switch is: R1(1.52)<8-3>[3]*waaren wrote: ↑Thursday 22 October 2020 7:56Can you define not successful.. ?abdolhamednik wrote: ↑Thursday 22 October 2020 7:52 i followed it and wrote this short script, test, but it was 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?
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
- 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
When I use that name in the script and save it as dzVents, I seeabdolhamednik 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
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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- 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
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)
.
.
.
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)
.
.
.
- 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
Did you set your location details in [Setup][Settings][Systems] ? If not domoticz / dzVents cannot determine the local time and everything derived from it.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)
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
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 0 guests