Getting value from JSON into device

User avatar
roquej
Posts: 628
Joined: Sun Jan 04, 2015 4:56 pm
Location: South Florida, USA

Getting value from JSON into device

Post by roquej »

Mr. MQTT Jedi, while you have a chance to work on the Nexia plugin, I am trying to get a few details from my Nexia thermostat using MQTT and Home Assistant. Got the temperature and humidity without any issues. However, having a problem understanding how to get the "system status", a string, configured.

The topic looks like this:
Screen Shot 2021-10-18 at 9.30.08 AM.png
Screen Shot 2021-10-18 at 9.30.08 AM.png (50.45 KiB) Viewed 2007 times
So, trying to configure the device as such:

Device type: Generic JSON
Screen Shot 2021-10-18 at 9.30.08 AM.png
Screen Shot 2021-10-18 at 9.30.08 AM.png (50.45 KiB) Viewed 2007 times
What am I doing wrong?

Thank you!!

JP
Attachments
Screen Shot 2021-10-18 at 9.36.23 AM.png
Screen Shot 2021-10-18 at 9.36.23 AM.png (163.38 KiB) Viewed 2007 times
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: Getting value from JSON into device

Post by FlyingDiver »

It doesn't look like you're showing the complete topic string there. It easier to see what's going on if you configure the MQTT Connector plugin to subscribe to the topics you want, then put it in debug level logging so it logs the topics and payloads.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
roquej
Posts: 628
Joined: Sun Jan 04, 2015 4:56 pm
Location: South Florida, USA

Re: Getting value from JSON into device

Post by roquej »

This is from the debug mgs and exactly the info I would like to collect via a Shims device:

processMessages: '##haSensors##' homeassistant/sensor/house_system_status/state -> System Idle

is this enough to point me in the right direction?

JP
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: Getting value from JSON into device

Post by FlyingDiver »

From that, it looks like the payload for that topic is NOT a JSON string, but a plain text string. I'm not sure the Shims plugin can deal with that the way you want. Is there any way to get HA to send actual JSON?
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
roquej
Posts: 628
Joined: Sun Jan 04, 2015 4:56 pm
Location: South Florida, USA

Re: Getting value from JSON into device

Post by roquej »

Not sure, but I will check. Will let you know

Thank you!
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: Getting value from JSON into device

Post by FlyingDiver »

If not, you can modify this script to get the payload and put it in a variable. Edit as needed and run as an external script.

Code: Select all

#! /usr/bin/env python
# -*- coding: utf-8 -*-
####################

import json
import time
import indigo

mqttPlugin = indigo.server.getPlugin("com.flyingdiver.indigoplugin.mqtt")
if mqttPlugin.isEnabled():
    props = {
        'message_type':"#Test#" 
    }
    while True:
        message_data = mqttPlugin.executeAction("fetchQueuedMessage", deviceId=1867973662, props=props, waitUntilDone=True)
        if message_data != None:
            indigo.server.log("Queue Fetch, version = {}, message_type = {}, topic_parts = {}".format(message_data["version"], message_data["message_type"], message_data["topic_parts"]))
            payload = json.loads(message_data["payload"])
            indigo.server.log("Queue Fetch, payload = {}".format(payload))
        else:
            time.sleep(1.0)
The deviceid in the call to mqttPlugin.executeAction() is the MQTT Connector device.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
roquej
Posts: 628
Joined: Sun Jan 04, 2015 4:56 pm
Location: South Florida, USA

Re: Getting value from JSON into device

Post by roquej »

as always, you rock!! thank you!

JP
Post Reply

Return to “MQTT”