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

Moderator: leecollings

Post Reply
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

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

Post 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
raverlution
Posts: 2
Joined: Sunday 23 October 2016 15:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
evertide
Posts: 14
Joined: Wednesday 19 November 2014 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Contact:

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

Post by evertide »

Hi,

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

Regards
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest