Backup/save the value/state of a switch

Post Reply
bldewit
Posts: 4
Joined: Tuesday 09 May 2017 23:31
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Backup/save the value/state of a switch

Post by bldewit » Wednesday 10 May 2017 0:29

Hi,
I want to save the value/state of a switch to a dummy switch when flipping another switch, so that I can reset it to that value later. I have tried to simply state SET <backupswitch> = <primaryswitch>, but that didn't work.

So I created a new blocky triggered by one switch and checking the value of the primary, then based on that setting the backup. Since that didn't work either I added a "fake" check for time, resulting in the following blocky:
[img]
blocky bckp.jpg
blocky bckp.jpg (23.61 KiB) Viewed 637 times
[/img]

Can anyone see the reason why this blocky does not work? (I have obviously activated it... :D and remember that I also tried this without the time-check )

Thanx!

ben53252642
Posts: 219
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version:
Contact:

Re: Backup/save the value/state of a switch

Post by ben53252642 » Wednesday 10 May 2017 2:28

The way I do this is to save the state to a variable using Lua:

See below:

Code: Select all

commandArray = {}
if (devicechanged['DEVICENAME'] == 'On') then
commandArray['Variable:DishwasherState'] = 'inuse'
end
return commandArray
The way you access the variable state is like this:

Code: Select all

commandArray = {}
if (uservariables["DishwasherState"] == 'notinuse') then
WHAT YOU WANT TO DO
end
return commandArray
This is my entire script for the dishwasher which uses a variable to store the state you mention:

Code: Select all

commandArray = {}

 -- Change Watt Device value to number and remove the word Watt
wattdevice = otherdevices_svalues['Dishwasher Watts']
function stripchars(str, chrs)
   local s = str:gsub("["..chrs.."]", '')
   return s end
wattvalue = stripchars( wattdevice, " Watt" )

if (uservariables["DishwasherState"] == 'notinuse' and tonumber(wattvalue) >= 3 ) then
commandArray['Variable:DishwasherState'] = 'inuse'
os.execute ('sh /root/domoticz/speak.sh "speaker3 Washing the dishes."')
end

if (uservariables["DishwasherState"] == 'inuse' and tonumber(wattvalue) <= 2 ) then
commandArray['Variable:DishwasherState'] = 'notinuse'
os.execute ('sh /root/domoticz/speak.sh "speaker3 The dishwasher has finished."')
commandArray['SendNotification']='Hawknet#The dishwasher has finished.'
end

return commandArray
Change the IP to your IP: http://192.168.0.5/#/UserVariables

The above URL is where you can set uservariables in Domoticz.

In the above example the variable type is "String", you can set it on the uservariables page.

Hope these examples help.

bldewit
Posts: 4
Joined: Tuesday 09 May 2017 23:31
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Backup/save the value/state of a switch

Post by bldewit » Wednesday 10 May 2017 20:45

Looks like a sound suggestion. Adding some nested if's could just do the job. I'll be checking this out these next days, thx!
Just to increase my understanding: What is the trigger for the bottom script in your answer?

bldewit
Posts: 4
Joined: Tuesday 09 May 2017 23:31
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Backup/save the value/state of a switch

Post by bldewit » Saturday 20 May 2017 0:00

Ok, so thanks to your suggestion I have been able to solve my problem while actually learning something about Lua scripts, thx! I didn't use a uservariable as you did, but another dummy switch.

I have found that using Lua actually gives you more grip on which switches of events are actuaally used as a trigger and which are just used for reference.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest