Hi,
I try to set an input_select when a modbus sensor changes.
Reverse order works (first automation), I can change the modbus registry when the input_select changes.
Also, when i put the value hardcoded to ‘’ it works.
So the actual problem is the template.
If anyone can review my code and tell me whats wrong, that would be helpfull.
This is my code:
- alias: Set Victron mode from input_select
trigger:
platform: state
entity_id: input_select.victron_mode
action:
service: modbus.write_register
data_template:
hub: victron_roadship
unit: 246
address: 33
value: >
{% if is_state("input_select.victron_mode", "Charge from AC only") %}
1
{%-elif is_state("input_select.victron_mode", "Invert only") %}
2
{%-elif is_state("input_select.victron_mode", "Charge from AC and invert") %}
3
{%-elif is_state("input_select.victron_mode", "Off") %}
4
{% endif %}
- alias: Set victron mode input_select from modbus sensor
trigger:
platform: state
entity_id: sensor.mode_switch_position_raw
action:
service: input_select.select_option
data:
entity_id: input_select.victron_mode
option: >
{% if is_state("sensor.mode_switch_position_raw", "1" %}
'Charge from AC only'
{%-elif is_state("sensor.mode_switch_position_raw", "2" %}
'Invert only'
{%-elif is_state("sensor.mode_switch_position_raw", "3" %}
'Charge from AC and invert'
{%-elif is_state("sensor.mode_switch_position_raw", "4" %}
'Off'
{% endif %}
Cheers,
Tom