It took me several hours of searching and trying, but I managed to solve it! The trick was: deviceinfo[1].activity.label
To complete this topic for future reference:
- I'm running Domoticz and HA bridge on my Synology NAS
- I have a Harmony hub connected to Domoticz via HA bridge (as native connection in Domoticz settings>hardware seemed to create an unstable system for some people, and I need HA bridge anyway so that I can manage activities via Alexa). This means i can switch my activities on and off in Domoticz via HA bridge.
- The problem with this is that when I use the harmony handheld remote control to start or stop an activity, my switches don't get updated. So when i used Domoticz to switch the activity "watch TV" on but used the handheld remote control to end the activity, the activity is still shown in Domoticz as "on".
- To solve this I used dummy switches and read out the harmony hub status via the LUA script i started this topic for. The reason for using the dummy switches is because you can then change the device status without it sending the switch command. In order to set this up, do as follows:
- Starting point is that you have Domoticz running, HA bridge running, and your harmony activities are in Domoticz as on/off switches.
- Create a dummy switch for every activity (as an example I will use the "watch TV" activity), in this case a dummy switch called "Watch TV slave".
- Then edit the original "Watch TV" switch, and define a sub/slave device, in this case you define "Watch TV slave" as a sub/slave of the "Watch TV" switch. Repeat this for your other activity switches
- Go to settings > more options > events and create a new LUA time event. Remove all the standard example code and paste the following code in there:
Code: Select all
commandArray = {}
json = (loadfile '/usr/local/domoticz/samplescripts/lua/JSON.lua')() -- check where your JSON.lua file is located on your sytem
file = assert(io.popen('curl "http://192.168.1.10:8080/api/devices/harmony/show"')) -- Change this to your IP:port of HA bridge
raw = file:read('*all')
file:close()
deviceinfo = json:decode(raw)
label = deviceinfo[1].activity.label
print("The current Harmony Hub activity is: " .. label)
if label == "Watch TV" then
commandArray['Watch TV slave']='On'
commandArray['Watch DVD slave']='Off'
elseif label == "Watch DVD" then
commandArray['Watch TV slave']='Off'
commandArray['Watch DVD slave']='On'
elseif label == "PowerOff" then
commandArray['Watch TV slave']='Off'
commandArray['Watch DVD slave']='Off'
else
print("Hub status UNKNOWN OR NOT IN EVENT SCRIPT")
end
return commandArray
- Make sure you changed the JSON.lua location and HA bridge IP and port to your setup. Tick "event active" and press save.
The slave switches should now update according to the current status of the Harmony Hub. You can check the log (in Domoticz > settings > log) to see if there are any errors or what the label of the current activity is.
The script will update every minute, so there is a delay of max 60 seconds before the status of the switches will be updated. Maybe this can be done in a more clever way (that the script runs when the label changed for example) but i don't have the skills for that. Suggestions and comments are always welcome
Many thanks to Nautilus for helping me in the right direction!
Gr. Ingmar
Synology NAS with stable release, AEON Z-wave, RFXCOM, Toon, Echo Dot, HAbridge, HarmonyHUB, Dashticz.