smar000 / evoGateway

Python script for listening in and responding to evohome heating control radio messages
46 stars 17 forks source link

Question: Is it possible to influence the granularity of topics? #47

Closed eddgrant closed 1 year ago

eddgrant commented 1 year ago

Hi there,

I'm just starting to get familiar with evoGateway (thanks for creating it!). I would like to use it to store TRV battery level information to InfluxDB. Looking at the data that gets published over MQTT I can see the following topic structure:

evohome/evogateway/master_bed/trv_zone_01_trv:123456/device_battery/battery_level
evohome/evogateway/master_bed/trv_zone_01_trv:123456/device_battery/battery_low
evohome/evogateway/master_bed/trv_zone_01_trv:123456/device_battery/device_battery_ts

Ideally I would like to store a single data point each time I get battery level information, preferably this would have the following:

I can probably do something complicated and try and join messages from multiple topics, but I wondered if there was a way of configuring evoGateway to do this e.g. if it were to publish messages to a topic such as:

evohome/evogateway/master_bed/trv_zone_01_trv:123456/device_battery

And send a message in the form:

{
  "timestamp": "<some timestamp>",
  "battery_low": false,
  "battery_level": 0.37
}

Most grateful if you have any thoughts on how I might go about achieving this!

Edd

smar000 commented 1 year ago

Hi Edd

Try adding the following to your config file and see if this helps:

MQTT_PUB_KV_WITH_JSON = True

This should give you a json result with all the endpoints for the given topic combined (in addition to the individual endpoints).

eddgrant commented 1 year ago

Thanks for the super quick response, will give that a whirl.

eddgrant commented 1 year ago

Hey @smar000, I have just tried adding that configuration setting, but I didn't see any new topics appear. I then looked through the code and couldn't find any reference to MQTT_PUB_KV_WITH_JSON. Is that definitely the config property name?

smar000 commented 1 year ago

Hi @eddgrant

I am currently abroad and so will have to check once I return later in the week, but I suspect that I have not pushed the current version I am running. That key is definitely there in my version.

smar000 commented 1 year ago

Hi @eddgrant

I've just merged my current working branch. Please try this and see if the data comes through as above.

eddgrant commented 1 year ago

Sorry for the delay in replying @smar000 . Appreciate you pushing these changes. I've been unable to test this yet but will do soon and will report back. Cheers!

eddgrant commented 1 year ago

Hey @smar000,

I've given this a test and can see the key / value pairs being grouped together in the messages now, which is great!

However I noticed that the _ts (timestamp) values are not included in the message. I've had a bit of a play around and think there's a simple way of achieving this, simply by re-ordering where the timestamp is created and including it in the message payload. I've implemented the change to test it on my fork here.

Would love to know if this is something you'd consider including? I'd be happy to raise a PR from my fork if so.

Many thanks,

Edd

smar000 commented 1 year ago

Hi @eddgrant

Great to hear that it is working for you, and thanks amendments, which I have just merged! :)

EDIT: Just realised it is not showing your name as the source of the changes. Apologies for that, I must have hit the merge before doing the pull request.

eddgrant commented 1 year ago

Hi @smar000 , great stuff, really appreciate you including the change 🙏

smar000 commented 1 year ago

Most welcome!