hi in esphome you can use subsitutions and variables… as i wanna be able to change 1 line in switch template and it just used through out… instead of needing to change swtich name 3 4 times
so my example is
switch:
- platform: template
switches:
dehumidifier_1:
friendly_name: "Dehumidifier 1"
value_template: "{{ is_state('switch.mini_plug_1', 'on') }}"
turn_on:
action: switch.turn_on
target:
entity_id: switch.mini_plug_1
turn_off:
action: switch.turn_off
target:
entity_id: switch.mini_plug_1
icon_template: >-
{% if is_state('switch.dehumidifier_1', 'on') %}
mdi:air-humidifier
{% else %}
mdi:air-humidifier-off
{% endif %}
and what i wanna do is
switch:
- platform: template
switches:
dehumidifier_1:
friendly_name: "Dehumidifier 1"
switchname: "switch.mini_plug_1"
value_template: "{{ is_state('{{switchname}}', 'on') }}"
turn_on:
action: switch.turn_on
target:
entity_id: { { switchname } }
turn_off:
action: switch.turn_off
target:
entity_id: { { switchname } }
icon_template: >-
{% if is_state('switch.dehumidifier_1', 'on') %}
mdi:air-humidifier
{% else %}
mdi:air-humidifier-off
{% endif %}
but of course it doesnt work that way… but can i do that ? does the template card let you do stuff like this where you can sub 1 line and it gets referenced so your not having to change multiple spots…
also trying to do color icon but it doesnt like it… i tried this
icon_color: >-
{% if is_state(switch.dehumidifier_1), 'on' %}
yellow
{% elif is_state(switch.dehumidifier_1), 'off' %}
green
{% else %}
blue
{% endif %}
1 post - 1 participant