Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Migrate to MQTT from HTTPS polling #16

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft

Migrate to MQTT from HTTPS polling #16

wants to merge 27 commits into from

Conversation

unlobito
Copy link
Owner

@unlobito unlobito commented Aug 12, 2020

The integration currently uses HTTPS polling to retrieve data from the CAD, but it'd be beneficial to use mqtt for real-time data instead.

This PR will cover implementing this in various stages:

will be used to retrieve the CAD hardwareId for MQTT
@unlobito unlobito mentioned this pull request Mar 26, 2021
@unlobito
Copy link
Owner Author

I think next up is refactoring Glow's constructor to accept the username/password from the restored ConfigEntry rather than a session token. Once the object has instance variables for the credentials, these can be used to calculate the MQTT connection URI (rather than the currently hardcoded USER:PASS).

Locally, this PR currently causes my HomeAssistant instance to console print the JSON messages received over MQTT (but the individual sensors report unavailable).

@unlobito
Copy link
Owner Author

Very rough on the edges, but we now have instantaneous electricity consumption being routed to an electricity sensor after MQTT autodiscovery.

imagen

MQTTPayload is heavily based on https://gist.github.com/ndfred/b373eeafc4f5b0870c1b8857041289a9, but I'd like to rewrite this to use a Colander schema instead of the if ... else None catches.

Afterwords, I'd like to route messages to sensors on a more unique key than the resource classifier (e.g. "electricity.consumption") so gas meters can be supported.


class Glow:
"""Bindings for the Hildebrand Glow Platform API."""

BASE_URL = "https://api.glowmarkt.com/api/v0-1"
HILDEBRAND_MQTT_HOST = "glowmqtt.energyhive.com"
HILDEBRAND_MQTT_TOPIC = "SMART/HILD/{hardwareId}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to make the MQTT topic configurable as well? Happy with HILD being the default, but for some reason I've got a legacy account and I need to use SMART/DCAD/{hardwareId}

Maybe name it mqtt_topic_prefix, that has a default value of HILD?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @bje 👋 Thanks for raising this! That's an interesting edge case. I wonder if there's some way to automatically discover the right topic.

In the meantime, it seems there aren't any issues from subscribing to both topics (and only receiving messages from one), so I've put that in db42193.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw- I've opened a post on the official forums seeking advice on properly discovering the MQTT topic https://forum.glowmarkt.com/index.php?p=/discussion/75/mqtt-topic-variations

@unlobito
Copy link
Owner Author

unlobito commented May 17, 2021

Today:

  • Attempted rewriting MQTTPayload in Colander but was unable to transparently rename the JSON key names (see stackoverflow/17975416)
  • Built out MQTTPayload with manual payload mapping
  • untested: attempted gas meter integration

I don't have a gas supply at home, so I'm eagerly looking for feedback on the gas readings added in 71af3ba. I've released this branch so far as https://github.com/unlobito/ha-hildebrandglow/releases/tag/0.1.0-beta for easier installation through HACS.

Next, will look into exposing more of the MQTT data as separate sensors so this PR can be released (services shouldn't hold this back).

heavily inspired by p1monitor and roombapy's design patterns
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants