Announcement

Collapse
No announcement yet.

HS Names from JSON payload

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    HS Names from JSON payload

    Michael:

    First let me say you have really outdone yourself, again, with the plugin. I was a long time user of your mcsXAP programs and this has that same look and feel.

    I just started using mcsMQTT (V5.1.1.7) over the weekend.

    I have a Raspberry Pi running JGYates's GENMON python scripts to monitor my Generac 22kW generator. This comes pre-built with an add-on for MQTT and that is how I plan on getting the generator status information into HS3.

    As of this morning I have MQTT running on HS and genmon program and passing data from the Pi to HS3. I am still experimenting but have several HS devices set up. The genmon MQTT program has the option to use JSON for numeric values and I have that enabled.

    So here's a sample of my HS devices:

    Click image for larger version

Name:	snip_20200316125624.png
Views:	231
Size:	16.4 KB
ID:	1370392

    For the first device, the battery voltage I manually went to the device management page in HS3 and changed the name of this device to "Battery voltage". I also manually added the suffix "V" to show the unt. The second device has not been touched and this leads me to my question:

    Is there a way to automatically parse the payload and change the name of the device within mcsMQTT. Looking at the address of the 2nd device, you'll see "generator/Status/Line/Utility Voltage/value". The name of this device should be "Utility Voltage". In addition to naming the device, I get the type and unit definition from the JSON decode which is shown below for the 2nd device shown above.

    Click image for larger version

Name:	snip_20200316130620.png
Views:	140
Size:	15.2 KB
ID:	1370393

    What would really be nice is if i could automatically set the name and add the "unit" as a suffix to the device so that, for instance, the device with reference 511 would end up looking like the device ref 512 where I manually changed the device in the device management page of HS3.

    I have read your PDF and perhaps I missed it, but did not find any reference to doing this particular operation on subscribed data.

    #2
    It looks to me as if the payload is not JSON. If it was JSON I would expect your Sub topic to look something like generator/Status/Line/Utility_Voltage:type rather than ending in /type/ It looks like "type" is part of the topic and not the payload. It does not matter as the behavior is the same either way.

    There are some widgets where the manufacturer has published the MQTT API and mcsMQTT has taken advantage of this to create the devices with minimum user action. There is also a discovery protocol that has been recently implemented using the Homeassistant discovery protocol. This allows a widget to advertise what it is (e.g. sensor with units of V and name Utility_Voltage on topic generator/Status/Line/Utility_Voltage). This information is then used by mcsMQTT to automatically create the device when the topic is observed.

    For other case a generic implementation is done and the user needs to take it the last mile to customize it for their needs.

    "unit" is a name that does not mean the unit of measure for all widgets so mcsMQTT will not in the general case look for it and put it as the device status suffix.

    The same type of analysis applies to the name of the device. Not all widgets use the 4th position of the topic as the widgets name. What I have done is intentionally made the name something that will not naturally be the final name, but something that makes it easy to initially correlate the Topic with the Device. In your example if "Utility Voltage" was used as the name then if both the type and the value were associated to devices then they would both have the same name initially in HS and it would be harder for a user to know which correlates with each.

    Comment


      #3
      Thanks Michael. Like I mentioned, everything is working for me so I'll just do the manual operation to get the name and units in my devices.

      Great Plugin!

      Comment

      Working...
      X