Page 1 of 1

LUA: Complex setup - Goes in on/off loop - need to 'get state'

Posted: Sunday 01 May 2016 12:29
by SoerenBM
Hi everyone,

I have a bit of complicated setup that consists of 4 different systems.

I want Domoticz to be the master system.

IHC Controller (part of the integrated electrical system of the house)
This system is the one that actually turns of/on lamps, plugs etc. via relays

IHC Captain (software running on RPi)
This software senses changes in the IHC Controller and when lights are turned on/off using physical switches sends an on or off command to update status in Domoticz via JSON ie. wget -qO- 'http://192.168.10.11:8080/json.htm?type ... itchcmd=On' &> /dev/null

OpenHAB (software running on Windows)
This software is used to manipulate the 'IHC Controller' as it has an IHC binding, when turning on/off lights in Domoticz.

Domoticz has the general overview - also used with RFXtrex433 for Somfy blinds.

I have made e LUA scripts that via os.execute calls an REST API on openHAB that again turns on the light in the IHC Controller.

What happens in some cases is it all goes in a loop and the light keeps turning on and off until i disable the LUA script.

The scripts

Code: Select all

commandArray = {}

openHAB_URL = 'http://192.168.10.4:8080/rest/items/'
openHAB_Devicename = 'Light_WalkIn_Loftlampe'
Domoticz_Devicename = 'Walk-in | Loftlampe'

if (devicechanged[''..Domoticz_Devicename..''] == 'On') then
     os.execute('curl --header "Content-Type: text/plain" --request POST --data "ON" '..openHAB_URL..''..openHAB_Devicename..' ')
elseif (devicechanged[''..Domoticz_Devicename..''] == 'Off') then
     os.execute('curl --header "Content-Type: text/plain" --request POST --data "OFF" '..openHAB_URL..''..openHAB_Devicename..' ')
end
return commandArray

Via the REST I can get a state if the lamps is on or off:
http://192.168.10.4:8080/rest/items/Lig ... ampe/state

I would like to use this state when i turn on/off in Domoticz - if the lamps is off exectue the os.execute command - of the lamps is already on do nothing.


I cannot get my head wrapped around to do this - I'm not a programmer

I've been trying with, but have not had any luck.

Code: Select all

f = assert (io.popen ("curl http://192.168.10.4:8080/rest/items/Light_WalkIn_Loftlampe/state"))
        for line in f:lines() do
        print(line)
    end -- for loop
f:close()
How can I use the output from the 'state' to do os.execute or not?

Thanks.

BR Søren

Re: LUA: Complex setup - Goes in on/off loop - need to 'get state'

Posted: Thursday 03 November 2016 12:59
by raverlution
Hello

Have you found a solution to your problem? or even better a more simpel sulution?

I am abut to build a similar setup, and so far i have the IHC binding in openhab up and running + homekit so i can use siri to turn on the light, i have also installed IHCcaptain and domoticz on the same rpi3, but i am not sure how to get i working so domoticz get updated about the status of the lamp etc.

i am also not a programmer:) and used several days to get the IHC binding in openhab to work properly + a few days to get the homekit to work :D

Re: LUA: Complex setup - Goes in on/off loop - need to 'get state'

Posted: Saturday 12 November 2016 22:22
by evertide
Hi,

Have a look at this post
http://www.domoticz.com/forum/viewtopic.php?t=8495

Regards