Update switch status using LUA

Moderator: leecollings

Post Reply
User avatar
mvveelen
Posts: 697
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Update switch status using LUA

Post by mvveelen »

Hi,

I have a bash script which can be used to control the airco units. This script van also be used to get the status of the units.

Code: Select all

./airco.sh 192.168.0.60 set power on
./airco.sh 192.168.0.60 set speed 2
./airco.sh 192.168.0.60 set mode cool
etc.
The status van be read:

Code: Select all

pi@pidomoticz:~ $ /home/pi/airco.sh 192.168.0.60 get speed
4
pi@pidomoticz:~ $ ./airco.sh 192.168.0.60 get power
1
pi@pidomoticz:~ $ ./airco.sh 192.168.0.60 get speed
4
pi@pidomoticz:~ $ ./airco.sh 192.168.0.60 get mode
4
pi@pidomoticz:~ $ ./airco.sh 192.168.0.60 get vane
10
pi@pidomoticz:~ $ ./airco.sh 192.168.0.60 get setpoint
220
etc.
And the results are always a number (220 = 22 degrees Celsius)

The Lua script I use:

Code: Select all

commandArray = {}

print('=========== airco script start ============')  

aircoValuePowerSK = os.execute('/home/pi/airco.sh 192.168.0.60 get speed')
commandArray['OpenURL'] = 'http://192.168.0.126:8080/json.htm?type=command&param=udevice&idx=735&nvalue=1&svalue=' .. aircoValuePowerSK;

print('=========== airco script eind ============')  

return commandArray
But, I get an error message:
Error: EventSystem: in Airco_status: [string "commandArray = {}..."]:6: attempt to concatenate global 'aircoValuePowerSK' (a boolean value)
How can this be fixed?

In short: I want the status in Domoticz to reflect the status also when I use the IR controller or the iPhone app. So, the corresponding value must be read (get) and then sent to the virtual switch in Domoticz.

I hope someone can help me out.
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Update switch status using LUA

Post by jvdz »

What About something like this?:

Code: Select all

commandArray = {}

print('=========== airco script start ============')
local f = assert(io.popen('/home/pi/airco.sh 192.168.0.60 get speed', 'r'))
local aircoValuePowerSK = assert(f:read('*a'))
f:close()
commandArray['OpenURL'] = 'http://192.168.0.126:8080/json.htm?type=command&param=udevice&idx=735&nvalue=1&svalue=' .. aircoValuePowerSK;
print('=========== airco script eind ============')

return commandArray
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
mvveelen
Posts: 697
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Re: Update switch status using LUA

Post by mvveelen »

Hi Jos,

thanks. I just saw your solution and I'm going to try it.

This is what I had:

Code: Select all

local aircoValuePowerZK = io.popen('/home/pi/airco.sh 192.168.0.61 get power') -- runs command
local aircoValuePowerZKval = aircoValuePowerZK:read("*a") -- read output of command
commandArray['UpdateDevice'] = "715|" .. tostring(aircoValuePowerZKval) .. "|" .. tostring(aircoValuePowerZKval) .. "|"



And that kinda works. But I'm having some troubles getting everything tied together, see: viewtopic.php?f=61&t=24287
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest