Page 1 of 1
Real switch vs. dummy-switch
Posted: Tuesday 07 June 2016 20:20
by OCB73
Hi!
I have 2 nearly identical scripts, one with a window/door-sensor and the other one with a dummy-switch.
The script with the real switch is only triggered when the window is opened or closed. The script with the
dummy-switch is triggered every 5-10 minutes. Is this normal?
If yes, can i do something, that the script is only triggered when the dummy-switch is switching?
Regards
Oliver
Re: Real switch vs. dummy-switch
Posted: Wednesday 08 June 2016 19:20
by OCB73
Here my scripts, hope it helps to solve my problem.
Window/Door-Sensor, named script_variable_fkt-kzeg.lua:
Code: Select all
local Thermostat = 'Thermostat Kinderzimmer EG'
local Fensterkontakt = 'Fensterkontakt Kinderzimmer EG'
commandArray = {}
if devicechanged[Fensterkontakt]=='On' then
commandArray['Variable:Thermostat Kinderzimmer EG'] = otherdevices_svalues[Thermostat]
commandArray[1]={['UpdateDevice']='28|0|15.0'}
elseif devicechanged[Fensterkontakt]=='Off' then
commandArray['UpdateDevice']='28|0|' .. tostring(uservariables['Thermostat Kinderzimmer EG'])
end
return commandArray
Dummy-Switch, named script_variable_ht-wz.lua
Code: Select all
local Thermostat = 'Thermostat Wohnzimmer'
commandArray = {}
if (devicechanged['Heizungssteuerung über Außentemperatur'] == 'On') then
commandArray['Variable:Thermostat Wohnzimmer'] = otherdevices_svalues[Thermostat]
commandArray[1]={['UpdateDevice']='5|0|15'}
elseif (devicechanged['Heizungssteuerung über Außentemperatur'] == 'Off') then
commandArray['UpdateDevice']='5|0|' .. tostring(uservariables['Thermostat Wohnzimmer'])
end
return commandArray
Regards
Oliver
Re: Real switch vs. dummy-switch
Posted: Thursday 09 June 2016 21:39
by jvdz
Why are the script file names starting with "script_variable" and not "script_device"?
Jos
Re: Real switch vs. dummy-switch
Posted: Friday 10 June 2016 12:37
by OCB73
Hmmm...maybe i understood something wrong...
thats the reason why:
viewtopic.php?t=9748#p68164
Regards
Oliver
Re: Real switch vs. dummy-switch
Posted: Friday 10 June 2016 12:54
by jvdz
That link is confusing for me. Maybe it is easier when you explain what it is you are trying to do and what is going wrong.
The 5-10 minutes trigger you describe is something I don't understand where that could come from. Does anything show up in the domoticz.log for that?
Either way: When you want to test for device changes you need to name your scripts script_device_xxxx.lua as described in the Events Wiki page:
https://www.domoticz.com/wiki/Events
Jos
Re: Real switch vs. dummy-switch
Posted: Friday 10 June 2016 13:25
by OCB73
Hi!
Again thx for fast reply...
I just posted the link cause you replied in that thread.
In case the thermostat only needs updating when a uservariable changes. the file should be named like script_variable_xxx.lua
Thats the reason for the name of my scripts.
My script for the real switch is working fine! The other script not, cause it´s triggered every 5-10 minutes.
Code: Select all
2016-06-10 12:46:08.954 EventSystem: Script event triggered: script_variable_ht-wz.lua
2016-06-10 13:01:36.063 EventSystem: Script event triggered: script_device_ht-wz.lua
2016-06-10 13:11:07.139 EventSystem: Script event triggered: script_device_ht-wz.lua
I have setup a dummy switch, which is going on/off depending from the outside-temp.
If outside-temp is over 20 degrees, switch is on and user-variable is updated, heating-valve is going down to 15 degrees.
If outside-temp is under 20 degrees, switch is off and heating-valve should go back to stored user-variable.
All is working, but when the script is triggered every 5-10 minutes, user-variable is set to 15 degrees.
Thats my problem.
Regards
Oliver
Re: Real switch vs. dummy-switch
Posted: Friday 10 June 2016 14:33
by jvdz
Ok, couple of observations/questions:
1. When you have a script triggered on a uservariable, it doesn't make sense to test for a devicechange (as that will never happen!), but rather test for the uservariable changed!
2. How is the user variable updated? Is that done through the Domoticz LUA event system or external script? A Lua script won't work as that never triggers a variable script. a JSON call will trigger it.
Jos
Re: Real switch vs. dummy-switch
Posted: Friday 10 June 2016 19:25
by OCB73
Am i so wrong with my script??? The first one is working fine!
Let me explain:
Thermostat = heating valve
Fensterkontakt = window/door-sensor
If the window/door-sensor goes on, the script saves the actual value of my heating-valve
to my uservariable and if the window/door-sensor goes off, the heating-valve goes to the
value stored in my uservariable. Thats exactly what i want and it´s working without a problem.
The script is only triggered when the window/door-sensor is switching.
But in the second one, there is no real switch! It´s a dummy-switch and it triggered every
5-10 minutes and not when the dummy-switch is switching from on to off or vise versa.
And exactly this is causing my problem.
Regards
Oliver
Re: Real switch vs. dummy-switch
Posted: Friday 10 June 2016 19:41
by jvdz
No worries about wrong or right here.
The thing I still don't understand how a script file called
script_variable_fkt-kzeg.lua is run by the event system when switch Fensterkontakt changes. This does not make sense to me.
Suggestion for that second script: Rename it to
script_device_ht-wz.lua which should then be ran whenever any device changes including the dummy switch.
Jos
Re: Real switch vs. dummy-switch
Posted: Friday 10 June 2016 19:53
by OCB73
You are really fast in answering!

I don´t now why it´s running but it´s running...i did all in Lua, maybe interesting.
I renamed both script around 13 o´clock, posted above, still the same.
2016-06-10 19:37:08.080 EventSystem: Script event triggered: script_device_ht-wz.lua
2016-06-10 19:47:09.155 EventSystem: Script event triggered: script_device_ht-wz.lua

- Lua
- Unbenannt.PNG (29.05 KiB) Viewed 3444 times
Regards
Oliver
Re: Real switch vs. dummy-switch
Posted: Friday 10 June 2016 20:22
by jvdz
Ah ok... you aren't using files but the internal scripts, so the name doesn't matter but rather the selection under the LUA box. So all clear now.

So that means that device 'Heizungssteuerung über Außentemperatur' is changing or else you wouldn't see these log entries.
What does the LOG show for that device?
Jos
Re: Real switch vs. dummy-switch
Posted: Friday 10 June 2016 21:25
by OCB73
2016-06-10 21:17:10 Off
2016-06-10 21:07:09 Off
2016-06-10 20:57:07 Off
... and so on. But why, i don´t understand that.
Oliver
Re: Real switch vs. dummy-switch
Posted: Friday 10 June 2016 21:51
by jvdz
So something is setting this Dummy switch to Off and seems to be a process that runs every 10 minutes.
Any CRON job running that could be setting this switch or any idea what process could setting it to Off?
Jos
Re: Real switch vs. dummy-switch
Posted: Saturday 11 June 2016 8:59
by OCB73
Good Morning!
I found my problem. It was caused by a logic problem in Blockly, which was caused by a Domoticz-Newbie.
I am the newbie and must say sorry. But maybe other newbies do the same mistake. So here is the logic
problem and what i have done:

- Blockly Event in combination with Netatmo causing my problem
- Unbenannt.PNG (8.17 KiB) Viewed 3378 times

- New Blockly Event, hopefully without problems
- Unbenannt2.PNG (12.68 KiB) Viewed 3378 times
This blockly-event is switching my dummy-switch on or off, depending on the outside-temp.
Many thanks for the help!!!
Regards
Oliver
Re: Real switch vs. dummy-switch
Posted: Saturday 11 June 2016 9:16
by jvdz
It's always simple ones you figured it out.
Jos
Re: Real switch vs. dummy-switch
Posted: Saturday 11 June 2016 10:27
by Egregius
Always check the status of the switch you want to switch to prevent repetitive commands

Re: Real switch vs. dummy-switch
Posted: Saturday 11 June 2016 11:01
by jvdz
Since you mentioned it: I am using the below LUA function to switch devices to ensure it only performs an actual change when the device has a different status. It just takes the devicename and a standard device command like On/Off/Set Status xx and any addon.
It will always create a Log entry so you know what happens why.
Jos
Code: Select all
function SwitchWhenDiff(DeviceName, iCommand)
-- retrieve current device status information
local dstatus = otherdevices[DeviceName]
local dvalue = tonumber(otherdevices_svalues[DeviceName])
if dvalue == nil then
dvalue = 0
end
if dstatus == nil then
dstatus = "??"
end
--
local Command = ""
local Level = 0
local Suffix = ""
-- check for valid starting command to perform
if string.sub(iCommand, 1, 2) == "On" then
Command = "On"
Level = 255
Suffix = string.sub(iCommand, 4)
elseif string.sub(iCommand, 1, 3) == "Off" then
Command = "Off"
Level = 0
Suffix = string.sub(iCommand, 5)
elseif string.sub(iCommand, 1, 9) == "Set Level" then
Command = "Set Level"
Level = tonumber(string.sub(iCommand, 11, 13))
Suffix = string.sub(iCommand, 11)
else
-- unknown command exiting
print("!### SwitchWhenDiff Unknown command for DeviceName:" ..DeviceName .."| iCommand:" .. iCommand .."|")
return
end
-- ensure we don't have any nil values to avoid errors
if Level == nil then
Level = 0
end
if Suffix == nil then
Suffix = ""
end
-- process information
print("!### SwitchWhenDiff DeviceName:" ..DeviceName .."| iCommand:" .. iCommand .."| Command:" .. Command .."| NewLevel:" ..tostring(Level).. "| Currentstatus:" ..dstatus .."| value:" .. dvalue)
if dstatus == nil then
-- invalid switch found
print(" ==> Invalid switchname " .. DeviceName .. " (" .. ScriptName .. ")")
elseif (dstatus == Command and dstatus == "Set Level" and dvalue >= Level - 3 and dvalue <= Level + 3) then
-- no change so don't do anything
print(" ==> Nothing to change for Dimmer (within margins +/-3) " .. DeviceName .. " (" .. ScriptName .. ")")
elseif (dstatus == Command and dstatus ~= "Set Level") then
-- no change so don't do anything
print(" ==> Nothing to change for " .. DeviceName .. " (" .. ScriptName .. ")")
elseif (Command == "On" and dstatus == "Set Level" and dvalue >= 0) then
-- no change so don't do anything: request an On command for Dimmer and it is already have a status of "Set Level" and percentrage GT 0
print(" ==> Nothing to change for dimmer " .. DeviceName .. " (" .. ScriptName .. ")")
else
--
print(" ==> Set " .. DeviceName .. " to:" .. iCommand .. " inx=" .. #commandArray + 1 .. " (" .. ScriptName .. ")")
commandArray[#commandArray + 1] = {[DeviceName] = iCommand}
end
return
end
Re: Real switch vs. dummy-switch
Posted: Monday 13 June 2016 12:34
by OCB73
Thx for the script. A little bit confusing for a beginner like me
at the moment, but later useful i think.
Oliver