Dummy Switch wont update as wanted

Moderator: leecollings

Post Reply
mrox
Posts: 11
Joined: Wednesday 18 October 2017 19:26
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Dummy Switch wont update as wanted

Post by mrox »

Hi,

i have a door switch that gives 1 or 0. I get the data from an API. For any reason my code below does not work as expected:

If value from door switch API = 1 and dummy switch == on, then set dummy switch Off

If value from door switch API = 0 and dummy switch == off, then set dummy switch On

Code: Select all

 
   if (tuergartenhaus == '1' and otherdevices['Tür Gartenhaus'] == 'On') then
        commandArray['Tür Gartenhaus'] = 'Off'
    end
    
    if (tuergartenhaus == '0' and otherdevices['Tür Gartenhaus'] == 'Off') then
        commandArray['Tür Gartenhaus'] = 'On'
    end
    
I guess it must be something stupid, but i cant get it to work.
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Dummy Switch wont update as wanted

Post by jvdz »

What type of device is the tuergartenhaus actually and does it really contain a string '1' or maybe rather have a value 1?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
mrox
Posts: 11
Joined: Wednesday 18 October 2017 19:26
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Dummy Switch wont update as wanted

Post by mrox »

Sorry for not beeing that precise! Here is the full code.

Code: Select all

commandArray = {}
now=os.date("*t")

if now.min % 1 == 0 then
   
   local stringTuerGartenhaus = assert(io.popen("curl -s http://10.168.2.60:8088/rest/devices/Tuerrkontakt/attributes/Tuer1/value" , 'r'))
   local tuergartenhaus = stringTuerGartenhaus:read('*all')
   
   if (tuergartenhaus == '1' and otherdevices['Tür Gartenhaus'] == 'On') then
        commandArray['Tür Gartenhaus'] = 'Off'
    end
    
    if (tuergartenhaus == '0' and otherdevices['Tür Gartenhaus'] == 'Off') then
        commandArray['Tür Gartenhaus'] = 'On'
    end
    
    print("Tuer Gartenhaus: "..tuergartenhaus)
end
return commandArray
This is in my log:

Code: Select all

2017-10-22 09:47:38.912 dzVents: Tuer Gartenhaus: 1
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest