MQTT and home-assistant

909 views
Skip to first unread message

Andrew Elwell

unread,
Dec 19, 2020, 5:14:01 PM12/19/20
to weewx...@googlegroups.com
Morning folks,

I've been running weewx with mqtt publisher for some time, and having recently done a complete refactor of my home-assistant configuration realised it's a bit of a pain to add each sensor to the configuration.

So: my plan is to patch the mqtt add-on to include a "enable home-assistant" configuration flag, and then get it to publish the configuration details as per https://www.home-assistant.io/docs/mqtt/discovery/

I had a quick look on GitHub and can see there are a few forks of Matthew's original (https://github.com/matthewwall/weewx-mqtt/network) - is anyone interested in picking up the suggestion or should I just fork and submit a PR in the normal manner? (Not sure if Matthew lurks on here)


Andrew

mwall

unread,
Dec 19, 2020, 6:10:49 PM12/19/20
to weewx-user
hi andrew,

i am still lurking.  i should (finally) be updating my weewx code as we go into 2021.  2020 has been brutal...

m

Richard G

unread,
Dec 20, 2020, 7:31:00 AM12/20/20
to weewx-user
I’d be interested in the HA integration, I’ve added a few values but it’s very tedious. Happy to test anything.

Richard

Andrew Elwell

unread,
Dec 20, 2020, 8:13:36 AM12/20/20
to weewx...@googlegroups.com
> I’d be interested in the HA integration, I’ve added a few values but it’s very tedious. Happy to test anything.

Work in progress screenshots on
https://twitter.com/elwell2000/status/1340642986955132929

It looks like I'll need to send the config payload every loop - this
doesn't seem to be an issue in home-assistant but otherwise (AFAICT)
the publisher doesn't have any advance indication of what key/value
pairs to expect to then publish. Related to this is the difficulty in
working out how to assign a 'device_class' to each of the measurements
- I can probably guess some via regexp (key ending _C is likely to be
temperature for instance)

anyhow, gardening took up most of the weekend, so I won't be pushing
my branch publicly till it's a bit less crufty. I'd *hope* to have
something others can test some things with by this time next week.

Andrew

vince

unread,
Dec 20, 2020, 1:46:28 PM12/20/20
to weewx-user
I'm a little lost re: what you're doing and why it's needed.

What i did was install the MQTT extension to weewx so that weewx emitted MQTT data to a MQTT broker running on a pi3.  I then subscribed to the readings I wanted in HA (temp/rain/wind) and added those elements to my HA dashboard.  Nice and simple.  Adding 'three' MQTT subscriptions to HA was trivial.  No fancy code or anything needed on either end.

Greg Troxel

unread,
Dec 20, 2020, 3:09:58 PM12/20/20
to vince, weewx-user
@rest of people: This message is not going to make sense if you don't
understand Home Assistant.


My impression of the goal is to support "mqtt discovery". Basically a
device posts a json dictionary to a config topic, and HA operates on
that data and adds sensors.

https://www.home-assistant.io/docs/mqtt/discovery/

and see "Sensors with multiple values". So the mqtt extension, which
perhaps has knowledge of all the items in the aggregate, would post to N
config topics, one for each item and then all the sensors would just
appear.

I post an aggregate message every archive interval, and I have 12
sensors configured from the large json dictionary that is published. I
ignore a bunch.

Obviously, if added, this facility should be optional in the weewx mqtt
extension. Some people, me included, don't want my sensor list spammed
with stuff they don't care about. I don't mind actual weather data, but
extraTemp4 when I don't have a sensor I defintely don't want. So
probably the extension needs to have some explicit config. This ends up
being a win if the programmatic config saves people time on average.

A comment I sent privately was that I want humiidty units to be "H%"
rather than "%", because when I look at graphs (in HA still) I want to
see humidities graphed together, and battery levels graphed together,
not all on one graph. (I even use V for line voltages, aV for
1.5V-nominal, bbV for 2 x 12V lead acid nominal, etc. Yes, I know I'm
unusual.)


All that said, I can completey see your point that you prefer to just
add a few sensors manually with template sensors.

signature.asc

wes...@gmail.com

unread,
Dec 21, 2020, 11:32:39 AM12/21/20
to weewx-user
i think this is a fantastic idea. what greg is doing is awesome.  i'd totally use this.

Andrew Elwell

unread,
Jun 27, 2021, 4:30:27 AM6/27/21
to weewx...@googlegroups.com
[holy thread resurrection, batman! Yes, I know it's taken longer than planned]

On Sun, 20 Dec 2020 at 09:13, Andrew Elwell <andrew...@gmail.com> wrote:
>
> So: my plan is to patch the mqtt add-on to include a "enable home-assistant" configuration flag, and then get it to publish the configuration details as per https://www.home-assistant.io/docs/mqtt/discovery/

I've started poking at this again, having spent some time working on a
similar thing for our EpEver solar charge controller. Well, that and
annoyance that weewx is saving the values from my FineOffset WS1080
(actually a https://www.jaycar.com.au/p/XC0348) with rounding errors

sqlite> select outTemp from archive order by dateTime desc limit 10;
8.5
8.45
8.46666666666667
8.45
8.5
8.56666666666667
8.68333333333334
8.7
8.7
8.76
sqlite>
but that's another days worry to work out where that's coming from.

Are there any particular functions that get called when weewx is
started, as I don't want to send the configuration every cycle.

Many thanks

Andrew
Reply all
Reply to author
Forward
0 new messages