sagaardu
(Sagaardu)
January 21, 2021, 4:08pm
1
Hello,
Do you know any way to modify the payload of the command topic in this type of thermostat?
I have seen in some old post that some used the mode_command_template parameter but it is no longer supported according to the documentation.
example of this parameter:
mode_command_template: >-
{% set values = { 'auto':'0', 'heat':'1', 'cool':'2', 'off':'4'} %}
{{ values[value] if value in values.keys() else '4' }}
The problem is that when I click on the flame icon, the payload that sends is heat and I need to modify it so that it sends a 1
This is my config:
climate:
- platform: mqtt
name: Salon
payload_on: 1
payload_off: 0
modes:
- "off"
- "heat"
mode_state_topic: "salon/get/Calefaccion"
mode_state_template: >-
{% set values = { '0':'off', '1':'heat'} %}
{{ values[value] if value in values.keys() else 'off' }}
mode_command_topic: "salon/set/Calefaccion"
current_temperature_topic: "salon/get/temperatura"
current_temperature_template: "{{float(value) / 100 }}"
temperature_command_topic: "salon/set/Consigna"
temperature_state_topic: "salon/get/Consigna"
temperature_state_template: "{{float(value) / 100 }}"
temp_step: 1
max_temp: 28
min_temp: 14
123
(Taras)
January 21, 2021, 4:47pm
2
I believe you maybe referring to the custom_component I made for MQTT HVAC that included (among other things) support for several command templates. The official MQTT HVAC integration does not, and never has, supported command templates for mode, fan_mode, hold, etc.
The technique I currently use is documented in this post:
Here’s my workaround for the lack of a command_template. This example is for mode_command_topic but it is the same principle for fan_mode_command_topic and hold_command_topic.
Set mode_command_topic to a ‘middleman’ topic like this:
mode_command_topic: 'temp/climate/hvac_mode'
Create an automation that subscribes to the ‘middleman’ topic, converts the received payload for use with your thermostat, and publishes it to your thermostat’s command topic.
- alias: 'hvac_mode controller'
tri…
Here’s an example of a single automation that handles the conversion of mode, fan_mode, and hold.
Click to show automation
- alias: 'Convert Climate'
mode: parallel
trigger:
- platform: mqtt
topic: temp/climate/hvac_mode
- platform: mqtt
topic: temp/climate/fan_mode
- platform: mqtt
topic: temp/climate/hold_mode
action:
choose:
- conditions: "{{ trigger.topic == 'temp/climate/hvac_mode' }}"
sequence:
service: mqtt.publish
data:
topic: thermostat/temperaturemode
payload: >
{% set values = { 'auto':'0', 'heat':'1', 'cool':'2', 'off':'4'} %}
{{ values[trigger.payload] if trigger.payload in values.keys() else '4' }}
- conditions: "{{ trigger.topic == 'temp/climate/fan_mode' }}"
sequence:
service: mqtt.publish
data:
topic: thermostat/fancontrol
payload: >
{% set values = { 'auto':'0', 'on':'1'} %}
{{ values[trigger.payload] if trigger.payload in values.keys() else '0' }}
- conditions: "{{ trigger.topic == 'temp/climate/hold_mode' }}"
sequence:
service: mqtt.publish
data:
topic: thermostat/mode
payload: "{{ '2' if trigger.payload == 'Hold' else '0' }}"
Alternately, you can wait for the following PR to be incorporated into a future release of Home Assistant. It adds several command templates to MQTT HVAC.
home-assistant:dev
← radovanbauer:climate
opened 01:59AM - 09 Jan 21 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Proposed change
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
This allows integrating with devices which require more complex payloads to be posted when updating their values.
Old (closed) feature request: https://github.com/home-assistant/core/issues/11496
There are numerous posts requesting this feature, example: https://community.home-assistant.io/t/need-help-with-value-template-for-mqtt-hvac/73395/68https://community.home-assistant.io/t/need-help-with-value-template-for-mqtt-hvac/73395/68
In my case this allows seamless support for https://github.com/tagyoureit/nodejs-poolController which needs specific json messages to be posted to command topics.
Command templates have been added for the following:
- fan_mode
- hold
- mode
- swing_mode
- temperature
- temperature high/low
This change doesn't add templates for aux, away mode, power since these already accept custom payload_on/off (although they all share the same payload). It should be straightforward to add templates for them as well if needed.
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [x] New feature (which adds functionality to an existing integration)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- This PR fixes or closes issue: fixes #11496
- This PR is related to issue:
- Link to documentation pull request: https://github.com/home-assistant/home-assistant.io/pull/16226
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [x] The code change is tested and works locally.
- [x] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] The code has been formatted using Black (`black --fast homeassistant tests`)
- [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] Untested files have been added to `.coveragerc`.
The integration reached or maintains the following [Integration Quality Scale][quality-scale]:
<!--
The Integration Quality Scale scores an integration on the code quality
and user experience. Each level of the quality scale consists of a list
of requirements. We highly recommend getting your integration scored!
-->
- [x] No score or internal
- [ ] 🥈 Silver
- [ ] 🥇 Gold
- [ ] 🏆 Platinum
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [ ] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/en/development_checklist.html
[manifest-docs]: https://developers.home-assistant.io/docs/en/creating_integration_manifest.html
[quality-scale]: https://developers.home-assistant.io/docs/en/next/integration_quality_scale_index.html
[docs-repository]: https://github.com/home-assistant/home-assistant.io
sagaardu
(Sagaardu)
January 21, 2021, 10:13pm
3
Thank you very much for the clarification
sagaardu
(Sagaardu)
January 25, 2021, 5:53pm
4
Hi friend,
Today I have created the automation following the example you gave but I can’t make it work. When I click on the flame icon (heat) the payload is still heat instead of 1.
This is my automation
- alias: 'Convert Climate'
mode: parallel
trigger:
- platform: mqtt
topic: salon/set/Calefaccion
action:
- service: mqtt.publish
data:
topic: salon/set/Calefaccion
payload: >
{% set values = { 'off':'0', 'heat':'1' } %}
{{ values[trigger.payload] if trigger.payload in values.keys() else '0' }
any suggestion why it doesn’t work?
Cheers
123
(Taras)
January 25, 2021, 6:09pm
5
sagaardu:
why it doesn’t work?
It doesn’t work because it’s using the same MQTT topic in the trigger and in the service call.
Look at my example again. The topic in the trigger is different from the topic in the service call.
Change the trigger’s topic to something different like temp/salon
- alias: 'Convert Climate'
mode: parallel
trigger:
- platform: mqtt
topic: temp/salon
Then set the climate entity’s mode_command_topic
to temp/salon
and restart Home Assistant.
mode_command_topic: "temp/salon"
The idea is this:
Climate entity -> temp/salon -> Conversion -> salon/set/Calefaccion
sagaardu
(Sagaardu)
January 26, 2021, 11:42am
6
Thank you very much again for the clarification, after you do the topic change and correct an error in the automation (I was missing a key at the end) I have managed to make it work.
a greeting
123
(Taras)
January 26, 2021, 1:09pm
7
I’m glad to hear the correction was successful and now it works.
For the benefit of other users, please consider marking my first post with the Solution tag. By doing this, it will automatically place a check-mark next to the topic’s title. This signals to other users that your problem has been resolved and has an accepted solution. This helps people find answers to similar questions.
sagaardu
(Sagaardu)
January 27, 2021, 10:22am
8
Hello,
The solution is totally valid, but it happens to me that after a while the thermostat goes back to off, even though everything is working.
123
(Taras)
January 27, 2021, 2:46pm
9
The configuration for climate.salon
contains this:
mode_state_topic: "salon/get/Calefaccion"
mode_state_template: >-
{% set values = { '0':'off', '1':'heat'} %}
{{ values[value] if value in values.keys() else 'off' }}
If it fails to receive either a 0
or a 1
it sets the mode to off
. You should investigate the values that are being published to salon/get/Calefaccion
.
In addition, when you use climate.salon
to set the mode, Home Assistant expects a prompt reply from the device, confirming the selected choice of mode. Make sure the device publishes its mode promptly.
sagaardu
(Sagaardu)
January 29, 2021, 12:14pm
10
OK, thank you very much for everything, I believe that thanks to you once again I have already detected the problem and it is indeed that the status topic sometimes receives an unexpected value.
Cheers