Create Switch for state_attr

Hello,

I would like to create a new Switch in which i can toggle between 2 “preset modes”.
The “ON” should be preset_mode to Eco
The “Off” should be preset_mode to None

But I’m stuck:

---
# Create a Switch to turn Panasonic Vloermodel preset_mode to ECO.
#
platform: template
    
switches:
  panasonic_vloedmodel_eco:
    friendly_name: "Panasonic Vloermodel Eco"
    value_template: "{{ is_state_attr('climate.panasonic_vloedmodel', 'preset_mode', 'eco') }}"
    turn_on:
      service: switch.toggle
      target:
        entity_id: switch.panasonic_vloedmodel_eco
    turn_off:
      service: switch.toggle
      target:
        entity_id: switch.panasonic_vloedmodel_eco

The climate.panasonic_vloermodel has the following attributen

hvac_modes:
  - 'off'
  - heat
  - cool
  - heat_cool
  - dry
  - fan_only
min_temp: 16
max_temp: 30
fan_modes:
  - Auto
  - Low
  - LowMid
  - Mid
  - HighMid
  - High
preset_modes:
  - none
  - boost
  - eco
swing_modes:
  - Auto
  - Up
  - UpMid
  - Mid
  - DownMid
  - Down
current_temperature: 24
temperature: 24
fan_mode: Auto
hvac_action: idle
preset_mode: eco
swing_mode: Auto
friendly_name: Panasonic Vloermodel
supported_features: 57

Aren’t you mixing up panasonic_vloedmodel ( in the template) and panasonic_vloermodel as name for the switch ?

Currently your actions for the template switch are turning the template switch itself on and off.

The actions should change the preset mode of your climate device:

turn_on:
  service: climate.set_preset_mode
  target:
	entity_id: climate.panasonic_vloedmodel
	preset_mode: 'eco'
1 Like

This did the trick:

---
# Create a Switch to turn Panasonic Vloermodel preset_mode to ECO.
#
platform: template
    
switches:
  panasonic_vloermodel_eco:
    friendly_name: "Panasonic Vloermodel Eco"
    value_template: "{{ is_state_attr('climate.panasonic_vloermodel', 'preset_mode', 'eco') }}"
    turn_on:
      service: climate.set_preset_mode
      target:
        entity_id: climate.panasonic_vloermodel
      data:
        preset_mode: 'eco'
    turn_off:
      service: climate.set_preset_mode
      target:
        entity_id: climate.panasonic_vloermodel
      data:
        preset_mode: 'none'