Feb-04-2023, 08:59 AM
(This post was last modified: Feb-04-2023, 08:59 AM by madpatrick.)
(Feb-03-2023, 08:29 PM)deanhystad Wrote:import json with open("test.txt", "r") as file: json_data = json.load(file) states = json_data["states"][0]["state"] for state in states: print( "id =", state["id"][0], "value =", state["tempValue"][0], "dhw", state["dhw"][0] )
Output:id = 0 value = 2000 dhw 1 id = 1 value = 1900 dhw 1 id = 2 value = 1700 dhw 1 id = 3 value = 1800 dhw 1 id = 4 value = 1000 dhw 1
Many thanks for your support.
This helped a lot
def onMessagetoonSceneinfo(self, Connection, Response): Domoticz.Debug("onMessagetoonSceneinfo called") if 'states' in Response: #this message contains the scenes Domoticz.Debug("onMessagetoonSceneinfo processing list of scenes") for state in Response["states"][0]["state"]: Domoticz.Log("id ="+ state["id"][0] + " Temp =" + state["tempValue"][0])
Output:2023-02-04 09:58:02.200 Toon: id =0 Temp =2000
2023-02-04 09:58:02.200 Toon: id =1 Temp =1900
2023-02-04 09:58:02.200 Toon: id =2 Temp =1700
2023-02-04 09:58:02.200 Toon: id =3 Temp =1800
2023-02-04 09:58:02.201 Toon: id =4 Temp =1000
Still getting this errorError:TypeError: list indices must be integers or slices, not str
How can i solve this?