Python Forum
Need help with coding in script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with coding in script
#1
Hi,

I'm trying to get the info for a JSON file in to a script.

    def onMessagetoonSceneinfo(self, Connection, Response):	
        Domoticz.Debug("onMessagetoonSceneinfo called")
        if 'states' in Response:
            for state in Response['states']['state']:
                self.scenes[state['id'][0]] = int(state['tempValue'][0])
But this gives the following error

Error:
2023-02-03 20:25:06.213 Error: for state in Response['states']['state']: 2023-02-03 20:25:06.213 Error: TypeError: list indices must be integers or slices, not str
The output of the JSON files is as follows

Output:
{ "states": [ { "state": [ { "id": [ "0" ], "tempValue": [ "2000" ], "dhw": [ "1" ] }, { "id": [ "1" ], "tempValue": [ "1900" ], "dhw": [ "1" ] }, { "id": [ "2" ], "tempValue": [ "1700"
Who can help me with this

Many thanks
Reply


Messages In This Thread
Need help with coding in script - by madpatrick - Feb-03-2023, 07:33 PM
RE: Need help with coding in script - by buran - Feb-03-2023, 07:39 PM
RE: Need help with coding in script - by madpatrick - Feb-03-2023, 07:43 PM
RE: Need help with coding in script - by deanhystad - Feb-03-2023, 08:13 PM
RE: Need help with coding in script - by madpatrick - Feb-03-2023, 08:21 PM
RE: Need help with coding in script - by deanhystad - Feb-03-2023, 08:29 PM
RE: Need help with coding in script - by madpatrick - Feb-04-2023, 08:59 AM
RE: Need help with coding in script - by snippsat - Feb-03-2023, 10:23 PM
RE: Need help with coding in script - by snippsat - Feb-04-2023, 12:14 PM
RE: Need help with coding in script - by madpatrick - Feb-05-2023, 04:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  coding error from a script (absolute noob) fuchls 2 3,947 Jun-08-2018, 02:29 PM
Last Post: webrunner1981

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020