Hi All,
I use checkFirst() lots of time. because it makes my scripts run faster. When it need to turn on or off lights for example.
But when you have other actions you cannot put the checkFirst() behind it.
Would it be nice that you can add checkFirst() always, no matter what?
Maybe that is possible to build?
checkFirst()
Moderator: leecollings
-
poudenes
- Posts: 667
- Joined: Wednesday 08 March 2017 9:42
- Target OS: Linux
- Domoticz version: 3.8993
- Location: Amsterdam
- Contact:
checkFirst()
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
-
jake
- Posts: 751
- Joined: Saturday 30 May 2015 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: checkFirst()
For other actions you have to know what the intended reaction is, before you can perform a 'checkfirst()'
-
poudenes
- Posts: 667
- Joined: Wednesday 08 March 2017 9:42
- Target OS: Linux
- Domoticz version: 3.8993
- Location: Amsterdam
- Contact:
Re: checkFirst()
When you do a action with .Kelvin() then it will turn on the light and then set Kelvin. When you add check first, it will skip the on action and directly set Kelvin. This is the same for RGB. Or create a new action CheckOnOff to check if a device is already on or off before doing the action.
I did some tests and when you want turn off 13 bulbs with the check first its much faster, because the script doesn't send for every bulb a off signal of its already off
I did some tests and when you want turn off 13 bulbs with the check first its much faster, because the script doesn't send for every bulb a off signal of its already off
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: checkFirst()
The speed advantage you see here is comparing the switchOff() function to switching regardless (without checking first if the device is already in the required state). To get a fair comparison, you should compare it with a user coded check.poudenes wrote: Sunday 06 January 2019 11:18 I use checkFirst() lots of time. because it makes my scripts run faster. When it need to turn on or off lights for example.
I checked both methods with a loop over +/- 100 devices with state Off and both methods take approximately the same amount of time (on average 275 milliseconds)
First test was with code using
Code: Select all
if device ~= "Off" then
device.switchOff()
end - Spoiler: show
Code: Select all
device.switchOff().checkFirst()- Spoiler: show
For some (sub)devices it would be possible but not very easy to do as the current implementation of this function is quite strongly linked to the switch devicetypes. Assuming there will also be no response improvement compared to the if construct like I showed in examples above a remaining reason would be to prevent the if construct in user code.But when you have other actions you cannot put the checkFirst() behind it. Would it be nice that you can add checkFirst() always, no matter what?
Maybe that is possible to build?
I see the value for switches because this requirement is there in many examples, but I have doubts about the added value for other devices.
As always; YMMD
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
-
poudenes
- Posts: 667
- Joined: Wednesday 08 March 2017 9:42
- Target OS: Linux
- Domoticz version: 3.8993
- Location: Amsterdam
- Contact:
Re: checkFirst()
Thanks for the reply and explanation 
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
-
rrozema
- Posts: 470
- Joined: Thursday 26 October 2017 13:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Delft
- Contact:
Re: checkFirst()
For me the main reason to use checkFirst() is a totally different one, still speed related though: if you do an update of a value, that may trigger all sorts of scripts to activate, even if you're setting the same value that was already there. So the main reason why I put checkFirst in my scripts is to avoid activating any triggers when the value doesn't change.
Who is online
Users browsing this forum: No registered users and 1 guest