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.