I’m sorry if this has been asked countless times, but I can’t seem to get this seemingly easy thing to work.
I have an MQTT sensor/number:
mqtt:
- name: "Nibe Modbus Register, Komfortmodus"
min: 0
max: 2
step: 1
state_topic: "nibe/modbus/47041"
command_topic: "nibe/modbus/47041/set"
The three possible values correspond to
0: “Sparmodus”
1: “Normal”
2: “Luxus”
I would like to have an input_select which lets me choose between those textual values.
I created an input select like this:
input_select:
nibe_hw_comfortmode_select:
name: Warmwasser Komfortmodus
options:
- "Sparmodus"
- "Normal"
- "Luxus"
icon: mdi:water-boiler
I then created two automations which are supposed to
- publish the correct MQTT payload when I change the input_select
alias: Nibe, Komfortmodus (Register) per Select setzen
description: ""
trigger:
- platform: state
entity_id:
- input_select.nibe_hw_comfortmode_select
condition: []
action:
- service: mqtt.publish
data:
topic: nibe/modbus/47041/set
payload: >
{% set options = {'Sparmodus': 0, 'Normal': 1, 'Luxus': 2 } %} {{
options[trigger.to_state.state] if trigger.to_state.state in
options.keys() else '0' }}
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
mode: single
- change the input_select based on the MQTT payload.
alias: Nibe Komfortmodus Select anpassen
description: ""
trigger:
- platform: state
entity_id:
- number.nibe_modbus_register_komfortmodus
condition: []
action:
- service: input_select.select_option
target:
entity_id: input_select.nibe_hw_comfortmode_select
data:
option: >
{% set options = {0: 'Sparmodus', 1: 'Normal', 2: 'Luxus' } %} {{
options[trigger.payload] if trigger.payload in options.keys() else
'Sparmodus' }}
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
mode: single
Somehow I am getting some kind of loop. When I change the input_select to “Normal” or “Luxus” (MQTT values 1 and 2), the mode gets changed to the correct one, but right after it switches back to “Sparmodus” (0).
Somehow the other way around doesn’t seem to work at all (changing my hot water mode on my heat pump). I do get the changed value in the MQTT number entity, the automation gets triggered, but the input_select doesn’t get changed.