Page 1 of 1

Multiple topics mapped to same Indigo Shim device?

PostPosted: Sun Jan 10, 2021 12:04 pm
by autolog
If I have messages such as:
Topic = topic1/device1/temperature, Raw payload = 24.50
Topic = topic1/device1/humidity, Raw payload = 80
Topic = topic1/device1/battery, Raw payload = 100
Is it possible to define a Shim for device1 and get the temperature mapped to the main UI state and the battery added as states of that device. Also if I was to create an equivalent humidity device based on device1, could I also get the battery mapped to a state for that device as well?

Re: Multiple topics mapped to same Indigo Shim device?

PostPosted: Sun Jan 10, 2021 12:07 pm
by FlyingDiver
No, not with individual topics with raw payloads. You can only get multiple values per device with JSON payloads.

I think. Let me check something...

Re: Multiple topics mapped to same Indigo Shim device?

PostPosted: Sun Jan 10, 2021 12:14 pm
by FlyingDiver
On second thought, this is probably a good place to try out the somewhat experimental aggregator feature in the connector plugin.

Use the Connector Plugin menu command "Manage aggregators". Create an aggregator with the topic base "topic1/device1". The get the device to emit all the possible topics/payloads. Then use the menu command "Print aggregator data to log". That'll show what the payload for that topic will be if you set up a trigger to send it to a shim.

Just be warned that the key paths for the various fields in the payload are not what you might think they would be. Look at the payload carefully.

Re: Multiple topics mapped to same Indigo Shim device?

PostPosted: Sun Jan 10, 2021 12:39 pm
by autolog
Trying it out now. :D

I am getting the payload:
Code: Select all
{"topics": {"battery": {"payload": 100}, "temperature": {"payload": 28.41}, "humidity": {"payload": 30}}}


What is the best way to set-up the Shim to pull out the three states: Battery, Temperature and Humidity?

I have tried this:
Screenshot 2021-01-10 at 18.36.11.png
Screenshot 2021-01-10 at 18.36.11.png (107.94 KiB) Viewed 1786 times
but I am getting an error:
Code: Select all
   Trigger                         he-temperature-02
   MQTT Shims Debug                received notification of MQTT message type ##he-temperature-02## from MQTT Connector
   Trigger                         he-temperature-02
   MQTT Shims Debug                received notification of MQTT message type ##he-temperature-02## from MQTT Connector
   Trigger                         he-temperature-02
   MQTT Shims Debug                received notification of MQTT message type ##he-temperature-02## from MQTT Connector
   MQTT Shims Debug                he-temperature-02: processMessages: '##he-temperature-02##' hubitat/home-hub-000d/he-temperature-02-sonoff-201 -> {"topics": {"battery": {"payload": 100}, "temperature": {"payload": 28.41}, "humidity": {"payload": 30}}}
   MQTT Shims Debug                he-temperature-02: update topic message_address = he-temperature-02-sonoff-201
   MQTT Shims Debug                he-temperature-02: update state_location_payload, key = topics.temperature.payload
   MQTT Shims Debug                recurseDict key_string = topics.temperature.payload, data_dict= {u'topics': {u'battery': {u'payload': 100}, u'temperature': {u'payload': 28.41}, u'humidity': {u'payload': 30}}}
   MQTT Shims Debug                recurseDict split[0] = topics, split[1] = temperature.payload
   MQTT Shims Debug                recurseDict key_string = temperature.payload, data_dict= {u'battery': {u'payload': 100}, u'temperature': {u'payload': 28.41}, u'humidity': {u'payload': 30}}
   MQTT Shims Debug                recurseDict split[0] = temperature, split[1] = payload
   MQTT Shims Debug                recurseDict key_string = payload, data_dict= {u'payload': 28.41}
   MQTT Shims Debug                he-temperature-02: shimValueSensor, key = topics.temperature.payload, data = {u'topics': {u'battery': {u'payload': 100}, u'temperature': {u'payload': 28.41}, u'humidity': {u'payload': 30}}}, value = 28.41
   MQTT Shims Debug                he-temperature-02: update adjustmentFunction: ''
   MQTT Shims Debug                he-temperature-02: Updating state to 28.41
   MQTT Shims Debug                recurseDict key_string = topics.battery.payload, data_dict= {u'topics': {u'battery': {u'payload': 100}, u'temperature': {u'payload': 28.41}, u'humidity': {u'payload': 30}}}
   MQTT Shims Debug                recurseDict split[0] = topics, split[1] = battery.payload
   MQTT Shims Debug                recurseDict key_string = battery.payload, data_dict= {u'battery': {u'payload': 100}, u'temperature': {u'payload': 28.41}, u'humidity': {u'payload': 30}}
   MQTT Shims Debug                recurseDict split[0] = battery, split[1] = payload
   MQTT Shims Debug                recurseDict key_string = payload, data_dict= {u'payload': 100}
   MQTT Shims Debug                he-temperature-02: update state_dict_payload_key, key = topics
   MQTT Shims Debug                recurseDict key_string = topics, data_dict= {u'topics': {u'battery': {u'payload': 100}, u'temperature': {u'payload': 28.41}, u'humidity': {u'payload': 30}}}
   MQTT Shims Debug                he-temperature-02: update, new states_list: Item : (list)
     Item : battery (string)
     Item : temperature (string)
     Item : humidity (string)
   MQTT Shims Debug                he-temperature-02: getDeviceStateList returning: States : (list)
     Item : (dict)
          Disabled : false (bool)
          Key : battery (string)
          StateLabel : battery (string)
          TriggerLabel : battery (string)
          Type : 150 (integer)
     Item : (dict)
          Disabled : false (bool)
          Key : temperature (string)
          StateLabel : temperature (string)
          TriggerLabel : temperature (string)
          Type : 150 (integer)
     Item : (dict)
          Disabled : false (bool)
          Key : humidity (string)
          StateLabel : humidity (string)
          TriggerLabel : humidity (string)
          Type : 150 (integer)
   MQTT Shims Error                Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 115, in runConcurrentThread
  File "plugin.py", line 139, in processMessages
  File "plugin.py", line 742, in update
TypeError: state value type must be bool, int, real, or string

   MQTT Shims Error                plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)
   SQL Logger                      adding column "batterylevel_ui" to table device_history_1363320665 ("he-temperature-02")
   SQL Logger                      adding column "battery" to table device_history_1363320665 ("he-temperature-02")
   SQL Logger                      adding column "humidity" to table device_history_1363320665 ("he-temperature-02")
   SQL Logger                      adding column "temperature" to table device_history_1363320665 ("he-temperature-02")
 

Re: Multiple topics mapped to same Indigo Shim device?

PostPosted: Sun Jan 10, 2021 12:43 pm
by FlyingDiver
You won't be able to use multi-states because of the way the payloads are nested. But you should be able to define a temp shim and a humidity shim, both showing battery status.

I had to do it that way because of varying topic lengths for the same topic base.

Re: Multiple topics mapped to same Indigo Shim device?

PostPosted: Sun Jan 10, 2021 1:05 pm
by autolog
I removed topics from Multi-States Key and am now getting this:
Screenshot 2021-01-10 at 19.00.53.png
Screenshot 2021-01-10 at 19.00.53.png (39.8 KiB) Viewed 1782 times

The custom states are listed but empty.
The battery status is being shown as 100% OK.

Is this what you would expect?

It will work for me in its current state. :D

Re: Multiple topics mapped to same Indigo Shim device?

PostPosted: Sun Jan 10, 2021 1:07 pm
by FlyingDiver
Yeah, it created those states before you changed the setup, but it wasn't able to populate them. If you created this device from scratch without the multi-states field, they wouldn't be there.

Re: Multiple topics mapped to same Indigo Shim device?

PostPosted: Sun Jan 10, 2021 1:09 pm
by autolog
Ok - thanks. :D

Re: Multiple topics mapped to same Indigo Shim device?

PostPosted: Sun Jan 10, 2021 3:26 pm
by autolog
As you suggested, I deleted and recreated the devices and now it is working perfectly.

The aggregator is a useful and nice feature! :)

Screenshot 2021-01-10 at 21.21.27.png
Screenshot 2021-01-10 at 21.21.27.png (41.8 KiB) Viewed 1704 times


No custom states now listed and both Indigo devices running off the same source device, a Sonoff temperature sensor. :D