turn a light to "Last state"?

Moderator: leecollings

Post Reply
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

turn a light to "Last state"?

Post by Evelen »

Hi.

Somtimes I want to change the status of a lamp, f.eks set the light to blue 100% dim for 1 sec, then change it back (as a notification, facebook ect)

eks:
- Color is red 24% dim
- facebook notification = set color blue 100% dim for 1sec
- Set Color back to red 24% dim
or:
- light is off
- facebook notification = set color blue 100% dim for 1sec
- light off


Is this posible? as easy as possible.
I only use Blockly until now, but maybe LUA must be used here?
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: turn a light to "Last state"?

Post by Egregius »

First store the current value in a variable or other cache system.
Set the new color and then read the variable again to set the old one.
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Re: turn a light to "Last state"?

Post by Evelen »

It sounds logical, but how?
toreandre
Posts: 91
Joined: Tuesday 19 January 2016 12:51
Target OS: -
Domoticz version:
Contact:

Re: turn a light to "Last state"?

Post by toreandre »

Evelen wrote:It sounds logical, but how?
Search for "store variable lua domoticz", i searched for this some time ago and found some examples og storing values with LUA.
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: turn a light to "Last state"?

Post by jvdz »

I use this function to temporary change a switch to something and then have it return to its previous state:

Code: Select all


commandArray = {}

-- Set lights on for a certain time and then revert back to the original state
function TempSwitchChange(DeviceName, Command, Level, TimeSecs)
	local dstatus = otherdevices[DeviceName]
	local dvalue = otherdevices_svalues[DeviceName]
	print("!###  TempSwitchChange DeviceName:" ..DeviceName .."   Command:" .. Command .." Level:" ..Level .." TimeSecs:" .. TimeSecs)
	print("                   Current status:" ..dstatus .."   dvalue:" .. dvalue)
	if dstatus == nil then
		-- invalid switch
		print(" ==>  Invalid switchname " .. DeviceName .. "  (" .. ScriptName .. ")")
	elseif (dstatus == Command and dstatus == "Set Level" and dvalue == Level) then
		-- no change so don't do anything
		print(" ==>  Nothing to change for " .. DeviceName .. "  (" .. ScriptName .. ")")
	elseif (dstatus == Command and dstatus ~= "Set Level") then
		-- no change so don't do anything
		print(" ==>  Nothing to change for " .. DeviceName .. "  (" .. ScriptName .. ")")
	else
		--
		if Command == "Set Level" then
			-- Set future status thorugh LUA
			print(" ==> Set " .. DeviceName .. " to:" .. Command .. " " .. Level .. "   inx=" .. #commandArray + 1 .. "  (" .. ScriptName .. ")")
			commandArray[#commandArray + 1] = {[DeviceName] = Command .. " " .. Level}
		else
			print(" ==> Set " .. DeviceName .. " to:" .. Command .. "   inx=" .. #commandArray + 1 .. "  (" .. ScriptName .. ")")
			commandArray[#commandArray + 1] = {[DeviceName] = Command}
		end
		if dstatus == "Set Level" then
			-- Set future status thorugh LUA
			print(" ==> Set " .. DeviceName .. " to:" .. dstatus .. " " .. dvalue .. " AFTER " .. tostring(TimeSecs).. "   inx=" .. #commandArray + 1 .. "  (" .. ScriptName .. ")")
			commandArray[#commandArray + 1] = {[DeviceName] = dstatus .. " " .. dvalue .. " AFTER " .. tostring(TimeSecs) }
		else
			print(" ==> Set " .. DeviceName .. " to:" .. dstatus .. " AFTER " .. tostring(TimeSecs).. "   inx=" .. #commandArray + 1 .. "  (" .. ScriptName .. ")")
			commandArray[#commandArray + 1] = {[DeviceName] = dstatus .. " AFTER " .. tostring(TimeSecs) }
		end
	end
	return
end

-- set lamp to 100 % for 5 minutes and than back to its original value
TempSwitchChange("LAMP","Set Level", "100","300")
-- set lamp on for 5 minutes and than back to its original state
TempSwitchChange("Lamp2","On", "","300")
return commandArray
Jos
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Re: turn a light to "Last state"?

Post by Evelen »

thanks jvdz.
where in the script should I put in information?
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: turn a light to "Last state"?

Post by jvdz »

Have you scrolled all the way down in the code and seen the examples I put in?

Jos
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: turn a light to "Last state"?

Post by G3rard »

jvdz wrote:I use this function to temporary change a switch to something and then have it return to its previous state:

Code: Select all


commandArray = {}

-- Set lights on for a certain time and then revert back to the original state
function TempSwitchChange(DeviceName, Command, Level, TimeSecs)
	local dstatus = otherdevices[DeviceName]
	local dvalue = otherdevices_svalues[DeviceName]
	print("!###  TempSwitchChange DeviceName:" ..DeviceName .."   Command:" .. Command .." Level:" ..Level .." TimeSecs:" .. TimeSecs)
	print("                   Current status:" ..dstatus .."   dvalue:" .. dvalue)
	if dstatus == nil then
		-- invalid switch
		print(" ==>  Invalid switchname " .. DeviceName .. "  (" .. ScriptName .. ")")
	elseif (dstatus == Command and dstatus == "Set Level" and dvalue == Level) then
		-- no change so don't do anything
		print(" ==>  Nothing to change for " .. DeviceName .. "  (" .. ScriptName .. ")")
	elseif (dstatus == Command and dstatus ~= "Set Level") then
		-- no change so don't do anything
		print(" ==>  Nothing to change for " .. DeviceName .. "  (" .. ScriptName .. ")")
	else
		--
		if Command == "Set Level" then
			-- Set future status thorugh LUA
			print(" ==> Set " .. DeviceName .. " to:" .. Command .. " " .. Level .. "   inx=" .. #commandArray + 1 .. "  (" .. ScriptName .. ")")
			commandArray[#commandArray + 1] = {[DeviceName] = Command .. " " .. Level}
		else
			print(" ==> Set " .. DeviceName .. " to:" .. Command .. "   inx=" .. #commandArray + 1 .. "  (" .. ScriptName .. ")")
			commandArray[#commandArray + 1] = {[DeviceName] = Command}
		end
		if dstatus == "Set Level" then
			-- Set future status thorugh LUA
			print(" ==> Set " .. DeviceName .. " to:" .. dstatus .. " " .. dvalue .. " AFTER " .. tostring(TimeSecs).. "   inx=" .. #commandArray + 1 .. "  (" .. ScriptName .. ")")
			commandArray[#commandArray + 1] = {[DeviceName] = dstatus .. " " .. dvalue .. " AFTER " .. tostring(TimeSecs) }
		else
			print(" ==> Set " .. DeviceName .. " to:" .. dstatus .. " AFTER " .. tostring(TimeSecs).. "   inx=" .. #commandArray + 1 .. "  (" .. ScriptName .. ")")
			commandArray[#commandArray + 1] = {[DeviceName] = dstatus .. " AFTER " .. tostring(TimeSecs) }
		end
	end
	return
end

-- set lamp to 100 % for 5 minutes and than back to its original value
TempSwitchChange("LAMP","Set Level", "100","300")
-- set lamp on for 5 minutes and than back to its original state
TempSwitchChange("Lamp2","On", "","300")
return commandArray
Jos
Thanks for sharing this script, very handy :D
I only get an error because ScriptName is not defined, so I added

Code: Select all

local ScriptName = "TempSwitchChange"
Not using Domoticz anymore
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest