carda21
(Paul)
August 19, 2024, 11:14am
1
Hi,
I have a Hot Water System talking to HA via MQTT. I am coming across from OpenHAB so still learning.
I have the following defined.
- mqtt
- number:
- name: "Hot Water Main - Mode"
unique_id: "hot_water_main_mode"
command_topic: "evoheat/HotWaterMain/mode/command"
state_topic: "evoheat/HotWaterMain/mode/state"
min: 0
max: 4
value_template: >-
{% set mapper = {
'0' : 'Off',
'1' : 'Eco',
'2' : 'Hybrid',
'3' : 'Boost',
'4' : 'Absorbtion' } %}
{% set state = states('number.hot_water_main_mode') %}
{{ mapper[state] if state in mapper else 'Unknown' }}
The above is throwing an error “Payload ‘2’ is not a Number”. I am a bit lost.
123
(Taras)
August 19, 2024, 6:20pm
2
You have designed your template to receive a number, find a matching value in the mapper
dictionary and then report a string value (Off, Eco, Hybrid, etc). An MQTT Number is meant for reporting numbers , not strings.
I think want you want is an MQTT Select . It receives a number and reports a corresponding string value. It allows you to select a different string value via the UI (or via a service call) and publishes a corresponding number to the command topic.
- select:
- name: "Hot Water Main - Mode"
unique_id: "hot_water_main_mode"
options:
- 'Off'
- 'Eco'
- 'Hybrid'
- 'Boost'
- 'Absorbtion'
state_topic: "evoheat/HotWaterMain/mode/state"
value_template: >-
{{ { 0: 'Off',
1: 'Eco',
2: 'Hybrid',
3: 'Boost',
4: 'Absorbtion' }.get(value|int(0), 'unknown') }}
command_topic: "evoheat/HotWaterMain/mode/command"
command_template: >-
{{ { 'Off': 0,
'Eco': 1,
'Hybrid': 2,
'Boost': 3,
'Absorbtion': 4 }.get(value, 'unknown') }}
In Developer Tools → States
In the UI
1 Like
carda21
(Paul)
August 28, 2024, 4:22am
4
Missed your reply…about to try. Will report back!
carda21
(Paul)
August 28, 2024, 4:32am
5
123:
- select:
- name: "Hot Water Main - Mode"
unique_id: "hot_water_main_mode"
options:
- 'Off'
- 'Eco'
- 'Hybrid'
- 'Boost'
- 'Absorbtion'
state_topic: "evoheat/HotWaterMain/mode/state"
value_template: >-
{{ { 0: 'Off',
1: 'Eco',
2: 'Hybrid',
3: 'Boost',
4: 'Absorbtion' }.get(value|int(0), 'unknown') }}
command_topic: "evoheat/HotWaterMain/mode/command"
command_template: >-
{{ { 'Off': 0,
'Eco': 1,
'Hybrid': 2,
'Boost': 3,
'Absorbtion': 4 }.get(value, 'unknown') }}
It worked a treat, thank you
1 Like