How to toggle entity attribute state on a dashboard

I’m newish to HA, though I know a little. I’m trying to automate my ducted heating system. One thing I’d like to do is be able to switch the mode of one of the dampers from ITC to Damper. This will let me switch from temperature control to percentage control of the dampers to override the system which I need to do occasionally. Right now I switch back to the native app, but I’d like to stop doing that.

Ideally I would like to toggle between the ITC and Damper modes with a fairly compact control so it’s easy on my phone dashboard, and have a visual representation of which mode it is currently in. I can’t work out how to add something on the dashboard to do this. I’m mostly using Mushroom Cards.

Can anyone suggest how I might do this?

I have found Input_Boolean but I can’t work out how to put it on a dashboard.

i dont have a climate entity, but there is a service “Climate: Set preset mode” you should be able to set up a button on the dashboard to set the mode (untested guess below)

  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: climate.set_preset_mode
      target: 
        entity: climate.itc_living
      data:
        preset_mode: itc
    show_state: true
    icon_height: 30px
    icon: mdi:valve
    name: Set ITC mode
    hold_action:
      action: none

That’s interesting, thanks @chris.huitema . Ideally I’d like a single button of switch that toggle between ITC and Damper modes.

I added this to my dashboard, doing my best to follow your guide. I understand at a high level what it’s saying around dictionary and values, but it would take me a bit of time to fully understand it and work out how to resolve it.

show_name: true
show_icon: true
type: button
Name: Set ITC mode
tap_action:
  action: call-service
  service: climate
  data:
    preset_mode: ITC
  target: climate.itc_living
entity: climate.itc_living
show_state: true

Here’s the error message

Error handling message: expected a dictionary for dictionary value @ data['target']. Got 'climate.itc_living'
required key not provided @ data['service']. Got None (invalid_format)

You could use an input select helper and set the two states in the helper. Then make an automation that calls the service to change them based on the input select.

Not in front of a computer right now but happy to provide an example later if needed.

Im not that good with dashboard stuff either…

i think the entity should have been entity_id: try this… i added a second button for now to switch between.

  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: climate.set_preset_mode
      target: 
        entity_id: climate.itc_living
      data:
        preset_mode: ITC
    show_state: true
    icon_height: 30px
    icon: mdi:valve
    name: Set ITC mode
    hold_action:
      action: none
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: climate.set_preset_mode
      target: 
        entity_id: climate.itc_living
      data:
        preset_mode: Damper
    show_state: true
    icon_height: 30px
    icon: mdi:valve
    name: Set Damper mode
    hold_action:
      action: none

Just playing with some other options,

Create an “Input Select” Helper, name it “climate_itc_living_preset”, add the states “ITC” and “Damper”.

create an automation, have the trigger set to the “state” of the input selector “climate_itc_living_preset” created above. don’t set the to or from fields. leave the conditions blank

under actions call the service climate.set_preset_mode, select the target, and under the preset mode type

{{ states('input_select.climate_itc_living_preset') }}

note: it will change that action to yaml as the GUI doest do templates.

Now you can add an “entities card” to your dashboard that will give you a nice dropdown box. whenever it changes it will call the service.

you could also have an automation so that when the state attribute of the climate.itc_living preset_mode changes it changes the input helper. you should be able to figure this out with the GUI options

Ah, I understand. I’ve gotten the dropdown showing the values I need, I’ve called it "input_select.livingdampermodeselect". It’s not quite working yet though.

Here’s my action

service: fan.turn_on
data:
  preset_mode: {{ states('input_select.livingdampermodeselect') }}
target:
  entity_id: fan.damper_living

Here’s the error message. Again I understand what it’s saying, but don’t know how to resolve it. Any tips?

Living Damper Mode Change: Error executing script. Invalid data for call_service at pos 1: value should be a string for dictionary value @ data['preset_mode']

Because I have four zones I would like to make it more compact. Based on what I’ve learned here I suspect I can use a button to do something similar, and change the button icon / color / something else to trigger the action.

yeah i see the problem… but cant figure it out…

if i put the {{ states(‘input_select.livingdampermodeselect’) }} into dev tools - tempate i get the string i expect to see… but for some reason the automation isn’t accepting it…

I can see the value changing in developer tools but the syntax in my action is incorrect. I don’t know enough about HA yet to fully understand, but I might work it out tomorrow. If someone else can spot it please let me know

When I put this action in

service: fan.turn_on
data:
  preset_mode: {{ states('input_select.livingdampermodeselect') }}
target:
  entity_id: fan.damper_living

Then save and re-open the action I see this - the preset mode changes.

service: fan.turn_on
data:
  preset_mode:
    '[object Object]': null
target:
  entity_id: fan.damper_living

I did a bit of testing, it seems the {{ states('input_select.livingdampermodeselect') }} way wont work

but changing to the trigger method does. and its probably a bit cleaner and more universal too

{{ trigger.to_state.state }}

This Chris, I appreciate your help :slight_smile:

Unfortunately it’s not working as we’d hoped. I’ve tried both of these, neither works.

After this first one is saved the preset mode part changes to what’s below the code block

service: fan.turn_on
data:
  preset_mode: {{ trigger.to_state.state }}
target:
  entity_id: fan.damper_living
  preset_mode:
    '[object Object]': null

I tried wrapping the preset mode in quotes.

service: fan.turn_on
data:
  preset_mode: ' {{ trigger.to_state.state }} '
target:
  entity_id: fan.damper_living

After the automation is saved and I go back into it the preset_mode changes to preset_mode: null

Here’s the error when the first one is executed. Looks like it’s passing the whole dictionary of values in rather than just the desired state. When I hard code a state ITC / Damper in it works.

Error executing script. Invalid data for call_service at pos 1: value should be a string for dictionary value @ data['preset_mode']

Hard coding the value works, but doesn’t use the value in the dropdown. It’s the looking that seems to be failing.

service: fan.turn_on
data:
  preset_mode: Damper
target:
  entity_id: fan.damper_living

how are you triggering the automation? from the button where you edit the automation or by changing the input select? or are you running it from a script? there needs to be the input select changing to trigger the automation so there is a value to set.

i set up a test case on my system using a light and setting an effect, it seems to work perfectly to set a value in the same way

perhaps try manually editing the automation in file editor to change the preset mode to the ’ {{ trigger.to_state.state }} ’ with the correct quotes.

this is my test code (full automation part)

id: '1658610905709'
alias: aaaa
description: ''
trigger:
  - platform: state
    entity_id:
      - input_select.dddd
condition: []
action:
  - service: light.turn_on
    data:
      effect: '{{ trigger.to_state.state }}'
    target:
      entity_id: light.dartboard_rgb
mode: single

Thanks Chris. I have a dropdown with the values Damper and ITC, both of which work when I hard code them into the action. I’ve tried that format and had no luck. I wonder if it’s something about the entity / service I’m using, the fan.turnon service. I use that service hard coded in a few places with no issues.

I’ll have a play with a button version when I get time. It’s a bit odd. It’s probably something subtle I’m doing wrong, as I’m not super experienced with HA.

type: entities
entities:
  - entity: input_select.livingdampermodeselect
title: Living Damper
theme: Mushroom Square

Error executing script. Invalid data for call_service at pos 1: value should be a string for dictionary value @ data['preset_mode']

image

Ok, I got it working :slight_smile:

I usually call the service “Fan Turn On” with a damper mode to change the mode, but for some reason that isn’t working with the dropdown. Calling climate.set_preset_mode (which you mentioned earlier) with the same parameter works fine. Definitely user error! Thanks for all your help @chris.huitema :slight_smile:

If I get a button working I’ll post the code for that as well.

service: climate.set_preset_mode
data:
  preset_mode: '{{ trigger.to_state.state }}'
target:
  entity_id: climate.itc_living

Im a little confused with your setup, i dont understand where the fan.turn_on service comes from? in your original post there is a climate.itc_living entitiy to target the service at?

Can you try adding a new automation, change to edit in YAML mode and paste this in - as is, and save.

alias: change_itc_mode
description: 'automation to change mode'
trigger:
  - platform: state
    entity_id:
      - input_select.livingdampermodeselect
condition: []
action:
  - service: climate.set_preset_mode
    data:
      preset_mode: '{{ trigger.to_state.state }}'
    target:
      entity_id: climate.itc_living
mode: single

it should target the entity in your original post and be triggered when you change the dropdown.

once you change the dropdown if you could have a look at the trace from the automation, click the > should show a result like the screenshot below (but this is for my light…)

1 Like

You’re absolutely right - I posted just a few minutes before your last reply. It seems to work in some actions, but not others, to change the damper mode. When I changed to your suggested entity / service it worked perfectly :slight_smile:

A simple button card to cycle all options of the input select

type: button
show_name: true
show_icon: true
show_state: true
icon: mdi:valve
tap_action:
  action: call-service
  service: input_select.select_next
  data: {}
  target:
    entity_id: input_select.livingdampermodeselect
entity: input_select.livingdampermodeselect

Thanks very much @chris.huitema , appreciate all your help! :slight_smile: I’ll try this when I have a bit of time. Looks like I need an input select on the same dashboard to make this work, right?

it doesnt need to be visible on a dashboard, it just has to be an entity.

like always there is 100 ways to do things, this was just a clean simple option that should be easy to modify to suit.

1 Like

Thanks again Chris :slight_smile:

Incidentally, the fan entity is how the electric dampers for the air conditioner are represented in HA. Using the climate service seems more reliable for operations though.