Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use templating within a call-service action to dynamically set service_data based on state #215

Open
davetoland opened this issue Jan 31, 2023 · 1 comment

Comments

@davetoland
Copy link

davetoland commented Jan 31, 2023

I'm trying to use templating within a call-service action to give a value in the service_data that's based on a current state.

I don't know if it's just that I'm not doing something right, or whether this just isn't supported, but I'd like to supply either the value "heat" (if the current state is "auto") or "auto" (if it's currently "heat"). The default toggle action for this entity is to switch between "heat" and "off" but I don't want it "off" - it should follow the schedule (auto), unless it's turned on ad-hoc (heat) when needed....

action_button:
  mode: custom
  show: true
  tap_action:
    action: call-service
    service: climate.set_hvac_mode
    service_data:
      entity_id: climate.office
      hvac_mode: |
        {% if is_state('climate.office', 'auto') %}
          "heat"
        {% else %}
          "auto"
        {% endif %}

Currently when the button is clicked, I get a message saying there's an invalid value for data['hvac_mode'] and that the needs to be one of the following "heat", "cool", "auto", "off", etc. I've tried removing the quotes around the values with no change.

I'm a developer, but new to Home Assistant, and I'm not sure how to debug this to see the actual payload being sent.

Any advice or suggestions for how to get around this issue another way are happily received

@cloverasx
Copy link

cloverasx commented Aug 8, 2023

I haven't delved into the wonder world of javascript and I know this comes a bit late, but as a workaround, you could have two conditional buttons:

# state = heat
conditional:
  conditions:
    entity: climate.office
    state: "heat"
  card:
    # add the button for if the state is "heat"
# state = auto
conditional:
  conditions:
    entity: climate.office
    state: "auto"
  card:
    # add the button for if the state is "auto"

Also, as a note, I'm not sure if it'll necessarily be the state you're looking for or the state attribute value of hvac_mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants