Good afternoon
I have a Shelly 2 in my house (https://shelly.cloud/ very nice, can also be flashed with Tasmota, but not compulsory as mqtt can be enabled)
Found out I can query some data using http://192.168.178.79/status where 192... is the IP address of this switch with has 2 relays
The output is in json.
I managed to retrieve a number of data via lua, but fail to get data for individual relays even though all data is visible in the json feedback
Data retrieved from 192..., in raw data:
the above makes is hard to see, so here is a screenshot with a much clearer json structure, I collapsed a few lines towards the end{"wifi_sta":{"connected":true,"ssid":"MYWIFISSID","ip":"192.168.178.79"},"cloud":{"enabled":false,"connected":false},"mqtt":{"connected":true},"time":"14:35","serial":1,"has_update":true,"mac":"MACOFTHESWITCH","relays":[{"ison":false,"has_timer":false,"overpower":false,"is_valid":true},{"ison":false,"has_timer":false,"overpower":false,"is_valid":true}],"rollers":[{"state":"stop","power":0.00,"is_valid":true,"safety_switch":false,"stop_reason":"normal","last_direction":"stop","current_pos":101,"calibrating":false,"positioning":true}],"meters":[{"power":0.00,"is_valid":true,"timestamp":1545921351,"counters":[0.000, 0.000, 0.000],"total":0}],"update":{"status":"pending","has_update":true,"new_version":"20181217-130502/v1.4.2@cc724b51","old_version":"20181219-171759/wifi_disconnects_again@90290083"},"ram_total":50488,"ram_free":38324,"fs_size":233681,"fs_free":158381,"uptime":86594}

What I'm trying to retrieve, and so fail at, is the status for the individual relays: i.e. retrieve separately the "ison" information for relay 0 and relay 1
This is my code, the lines with ison are failing.. values 0 and 1 are clearly unacceptable !
How then do I point to the right information ?!
Thanks to whoever will kindly help me out !
Code: Select all
commandArray = {}
if devicechanged['TestSwitch3'] then
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
-- API call
local config=assert(io.popen('curl "http://192.168.178.79/status"'))
local result = config:read('*a')
config:close()
output = json:decode(result)
MyUptime= output.uptime
SoftwareCurrent=output.update.old_version
SoftwareNew=output.update.new_version
SwitchHallStatus=output.relays.0.ison
SwitchPorchStatus=output.relays.1.ison
print(MyUptime)
print(SoftwareCurrent)
print(SoftwareNew)
print('SwitchHall is '..SwitchHallStatus)
print('SwitchPorch is '..SwitchPorchStatus)
end
return commandArray