Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose individual commands via MQTT topics #31

Closed
proddy opened this issue Mar 21, 2021 · 16 comments
Closed

expose individual commands via MQTT topics #31

proddy opened this issue Mar 21, 2021 · 16 comments
Labels
enhancement New feature or request

Comments

@proddy
Copy link
Contributor

proddy commented Mar 21, 2021

As a request from @glitter-ball , since all EMS-ESP commands need to follow the JSON format {cmd:"", data:"", id:""} it's hard to send individual commands, like from a component or trigger in HA. For example, when using HA's platform:mqtt in a switch component it can only send on/off payloads to a single command topic, like in this screenshot:

unknown

This feature is to expose all commands as individual MQTT topics by subscribing to them as for example:

[21] (Sub) topic=ems-esp/boiler/comfort
[22] (Sub) topic=ems-esp/boiler/wwactivated
[23] (Sub) topic=ems-esp/boiler/wwtapactivated
[24] (Sub) topic=ems-esp/boiler/wwflowtempoffset
[25] (Sub) topic=ems-esp/boiler/wwmaxpower
[26] (Sub) topic=ems-esp/boiler/wwonetime
[27] (Sub) topic=ems-esp/boiler/wwcircpump
[28] (Sub) topic=ems-esp/boiler/wwcirculation
[29] (Sub) topic=ems-esp/boiler/wwcircmode
[30] (Sub) topic=ems-esp/boiler/flowtemp
[31] (Sub) topic=ems-esp/boiler/wwsettemp
[32] (Sub) topic=ems-esp/boiler/heatingactivated
[33] (Sub) topic=ems-esp/boiler/heatingtemp
[34] (Sub) topic=ems-esp/boiler/burnmaxpower
[35] (Sub) topic=ems-esp/boiler/burnminpower
[36] (Sub) topic=ems-esp/boiler/boilhyston
[37] (Sub) topic=ems-esp/boiler/boilhystoff
[38] (Sub) topic=ems-esp/boiler/burnperiod
[39] (Sub) topic=ems-esp/boiler/pumpdelay
[40] (Sub) topic=ems-esp/boiler/maintenance
[41] (Sub) topic=ems-esp/boiler/pumpmodmax
[42] (Sub) topic=ems-esp/boiler/pumpmodmin

@proddy proddy added the enhancement New feature or request label Mar 21, 2021
@proddy proddy self-assigned this Mar 21, 2021
proddy added a commit that referenced this issue Mar 21, 2021
@proddy
Copy link
Contributor Author

proddy commented Mar 21, 2021

did a first rough implementation. It will create a lot of additional MQTT subscribes, but I think the ESP32 can handle it.

@glitter-ball
Copy link

OK. Should I look to implement it a better way in HA? Maybe scripting was a better option? Shout if/when you want me to test. Thanks!

@proddy
Copy link
Contributor Author

proddy commented Mar 21, 2021

haven't tested with HA but should work with latest dev build.

@MichaelDvP
Copy link
Contributor

I think for thermostat you should enhance with the tag, now thermostat/daytemp works only on default hc, better use thermostat/hc2/daytemp

@proddy
Copy link
Contributor Author

proddy commented Mar 21, 2021

I think for thermostat you should enhance with the tag, now thermostat/daytemp works only on default hc, better use thermostat/hc2/daytemp

yeah, spotted that too. thanks.

@MichaelDvP
Copy link
Contributor

The system/pin without id is also nearly useless (defaults to gpio0). Maybe skip this from direct subscribe?

@proddy
Copy link
Contributor Author

proddy commented Mar 21, 2021

also true. Adding the tag is going to be tricky since for the thermostat this is done dynamically when a HC is detected. And these subscribes are created when a device is added. So I think I'll just limit it to a few functions, either
a) by adding a parameter to the register_mqtt_cmd() to choose whether or not to create a new subscribe topic
or b) just hard-code it for the Boiler only and forget the other devices like system, thermostat, solar etc...

what shall I do?

@MichaelDvP
Copy link
Contributor

I think thermostat is the most used device to set a value. Imho stay with default hc is better than skip thermostat.
Option c: always add all 4 hc to thermostat.
The other devices solar, mixer have no commands for now. System commands are not used frequently used over mqtt, i think that can be skipt.

@proddy
Copy link
Contributor Author

proddy commented Mar 22, 2021

ok skipping 'system' and thermostat will use the default hc. Adding all the hc's 1-4 can create up to 14*4 additional subscribes.

@MichaelDvP
Copy link
Contributor

Adding all the hc's 1-4 can create up to 14*4 additional subscribes.

For my RC35 it's 4x22 subscribes for the hc. I tested this and heap (free/max.alloc) drops from 96.968 / 84.384 bytes without subscribes to 81.968 / 55.140 bytes with boiler, thermostat and all 4 hc. No issues so far, the esp32 can handle it, but it's a lot of memory allocated.

In #739 there is someone with 3 active hc now switching to esp32. I don't know if he needs the direct subscriptions.

Maybe add a setting to mqtt-settings to activate the subscriptions?

@MichaelDvP
Copy link
Contributor

The high memory usage is due to register all subscriptions also as mqtt-subfunctions. I skip this, only use queue_subscribe_message(topic); and strip the topic in on_message to the known function. With all hc subscriptions heap is now: 93.572 / 67.728 bytes.

@proddy
Copy link
Contributor Author

proddy commented Mar 22, 2021

ok! Let's go with that

@MichaelDvP
Copy link
Contributor

Ok, i need to clean up my test codes a bit, than i can push it. I've also added a mqtt setting below boolean format as subscribe format with selection general device topics, individual topics, main heating circuit, individual topics, all heating circuits. Rename it if you find a better naming.

@MichaelDvP
Copy link
Contributor

Ok, pushed, please check. With thermostats like RC20 with only a single heatingcircuit the setting does not have a effect, there will not /hc1/ tags added (can be changed by flagging the commands in thermostat).

@proddy
Copy link
Contributor Author

proddy commented Mar 22, 2021

ok, I'll check. I also changed a few web files so it'll probably merge clash somewhere

@proddy proddy removed their assignment Mar 22, 2021
@proddy
Copy link
Contributor Author

proddy commented Apr 6, 2021

tested and works. nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants