Nested json problems

Posted on
Mon Jan 16, 2023 7:02 am
siclark offline
Posts: 1961
Joined: Jun 13, 2017
Location: UK

Nested json problems

Hoping someone can help my memory, its been a while since using Shims

I am trying to create a generic value sensor and I see the multi states and battery updating, so I knows its reading the message, but I cant find the right value for the Payload Key field as its a nested json message. I want the sensor to show the value in thermostats.pos. is 4.7 below from the debug.

Code: Select all
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: wifi_sta, {'connected': True, 'ssid': 'CCIoT', 'ip': '192.168.0.221', 'rssi': -76}, <class 'dict'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: cloud, {'enabled': True, 'connected': True}, <class 'dict'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: mqtt, {'connected': True}, <class 'dict'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: time, 13:00, <class 'str'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: unixtime, 1673874001, <class 'int'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: serial, 76, <class 'int'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: has_update, True, <class 'bool'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: mac, 2C1165DABA8B, <class 'str'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: cfg_changed_cnt, 0, <class 'int'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: actions_stats, {'skipped': 0}, <class 'dict'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: thermostats, [{'pos': 4.7, 'target_t': {'enabled': True, 'value': 24.5, 'value_op': 8.0, 'units': 'C'}, 'tmp': {'value': 22.6, 'units': 'C', 'is_valid': True}, 'schedule': True, 'schedule_profile': 1, 'boost_minutes': 0, 'window_open': False}], <class 'list'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: calibrated, True, <class 'bool'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: bat, {'value': 100, 'voltage': 4.144}, <class 'dict'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: charger, False, <class 'bool'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: update, {'status': 'unknown', 'has_update': True, 'new_version': '20220811-152343/v2.1.8@5afc928c', 'old_version': '20220720-094550/v2.1.7@f9b0e22f', 'beta_version': None}, <class 'dict'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: ram_total, 97280, <class 'int'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: ram_free, 30584, <class 'int'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: fs_size, 65536, <class 'int'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: fs_free, 59292, <class 'int'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: uptime, 6108, <class 'int'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: fw_info, {'device': 'shellytrv-2C1165DABA8B', 'fw': '20220720-094550/v2.1.7@f9b0e22f'}, <class 'dict'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: ps_mode, 0, <class 'int'>
   MQTT Shims Debug                Shelly Dining TRV Valve copy: adding to states_list: dbg_flags, 0, <class 'int'>


tried lots in last 2 hours and no joy.
thanks
Simon

Posted on
Mon Jan 16, 2023 7:04 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Nested json problems

That's a list of dicts, so you need to specify the position in the list. I think that "thermostats.0.pos" is what you need.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jan 16, 2023 7:23 am
siclark offline
Posts: 1961
Joined: Jun 13, 2017
Location: UK

Re: Nested json problems

Tahnks for the quick reply.

I am also getting this, per the bottom, do I need to convert from string?
Code: Select all
states_list : (list)
          Item : wifi_sta (string)
          Item : cloud (string)
          Item : mqtt (string)
          Item : time (string)
          Item : unixtime (string)
          Item : serial (string)
          Item : has_update (string)
          Item : mac (string)
          Item : cfg_changed_cnt (string)
          Item : actions_stats (string)
          Item : thermostats (string)
          Item : calibrated (string)
          Item : bat (string)
          Item : charger (string)
          Item : update (string)
          Item : ram_total (string)
          Item : ram_free (string)
          Item : fs_size (string)
          Item : fs_free (string)
          Item : uptime (string)
          Item : fw_info (string)
          Item : ps_mode (string)
          Item : dbg_flags (string)
     status_action_payload :  (string)
     status_action_template :  (string)
     toggle_action_payload : toggle (string)
     uid_location : topic (string)
     uid_location_payload_key :  (string)
     uid_location_payload_key_note :  (string)
     uid_location_topic_field : 1 (string)
     uid_location_topic_field_note :  (string)
    [b] value_location_payload_key : pos (string)[/b]

Posted on
Mon Jan 16, 2023 7:33 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Nested json problems

Shouldn't need to. That's the list of items on the config dialog, and payload key field there is a string. The plugin already does a float() on the value it finds when using it in a value sensor.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jan 16, 2023 7:34 am
siclark offline
Posts: 1961
Joined: Jun 13, 2017
Location: UK

Re: Nested json problems

Thats what I thought, but still get zero. showing.
Attachments
Screenshot 2023-01-16 at 13.31.56.png
Screenshot 2023-01-16 at 13.31.56.png (494.3 KiB) Viewed 1660 times

Posted on
Mon Jan 16, 2023 7:41 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Nested json problems

Post the complete JSON payload you're getting and I'll set up a test shim for it and see what's going on.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jan 16, 2023 7:41 am
siclark offline
Posts: 1961
Joined: Jun 13, 2017
Location: UK

Re: Nested json problems

Cheers

Code: Select all
{"wifi_sta":{"connected":true,"ssid":"CCIoT","ip":"192.168.0.221","rssi":-76},"cloud":{"enabled":true,"connected":true},"mqtt":{"connected":true},"time":"13:41","unixtime":1673876480,"serial":33,"has_update":true,"mac":"2C1165DABA8B","cfg_changed_cnt":0,"actions_stats":{"skipped":0},"thermostats":[{"pos":100.0,"target_t":{"enabled":true,"value":25.5,"value_op":8.0,"units":"C"},"tmp":{"value":21.2,"units":"C","is_valid":true},"schedule":true,"schedule_profile":1,"boost_minutes":0,"window_open":false}],"calibrated":true,"bat":{"value":100,"voltage":4.144},"charger":false,"update":{"status":"unknown","has_update":true,"new_version":"20220811-152343/v2.1.8@5afc928c","old_version":"20220720-094550/v2.1.7@f9b0e22f","beta_version":null},"ram_total":97280,"ram_free":30576,"fs_size":65536,"fs_free":59292,"uptime":1938,"fw_info":{"device":"shellytrv-2C1165DABA8B","fw":"20220720-094550/v2.1.7@f9b0e22f"},"ps_mode":0,"dbg_flags":0}

Posted on
Mon Jan 16, 2023 8:45 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Nested json problems

Hmm. This is strange. I could have sworn that code handled mixed dicts and lists. I remember writing code to handle that. But it's not there. Which means I must have written that for some other plugin. But I can't find it. My memory must be playing tricks on me. Sigh.

So, it's not going to work until I can recreate that code and get an update out. Sorry.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jan 16, 2023 9:00 am
siclark offline
Posts: 1961
Joined: Jun 13, 2017
Location: UK

Re: Nested json problems

No worries. I thought for a moment I could make a rest api call from the device to Indigo to update a variable with the value in, but its running into an auth error

Looks like this one stays as a test device for now.

Posted on
Mon Jan 16, 2023 9:32 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Nested json problems

Sigh. The code was there, I just didn't recognize it. You want to use "thermostats.[0].pos". I needed to use the brackets to signify a list index because a bare number is a valid key in a dict.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jan 16, 2023 9:34 am
siclark offline
Posts: 1961
Joined: Jun 13, 2017
Location: UK

Re: Nested json problems

So funnily enough I had seen that syntax whilst looking at how to struture some commands to publish on the HA boards, had tried it on the device, but not gone back to check. But yes, that is now working. Thanks.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests