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

[FR]: Add state_actions that works like state_styles, state_icons and state_text #135

Open
luixal opened this issue May 17, 2023 · 2 comments

Comments

@luixal
Copy link

luixal commented May 17, 2023

Is your feature request related to a problem? Please describe.

I'm trying to buildd a row of buttons for an irrigation system. One of this buttons is a toggle (play/stop) button. I can make the button show a different icon and style according to state (playing/stopped), but I need to make a different service call according to the state:

Start irrigation:

action: call-service
service: irrigation_unlimited.manual_run
service_data:
  entity_id: binary_sensor.irrigation_unlimited_c1_z1
  time: 00:01:00 #<--- I don't need this param for pausing

Stop irrigation:

action: call-service
service: irrigation_unlimited.cancel
service_data:
  entity_id: binary_sensor.irrigation_unlimited_c1_z1

If I use templates (i.e: putting this card inside a button-card card) I get an error when stopping irrigation because of the extra time field.

Describe the solution you'd like

For my use case, if a value of none makes the time params not being sent in the service call would work for me.

I think a better solution would be to follow the style of state_styles, state_icons and state_text by providing an state_actions that allows you to perform different actions according to the state of the entity.

Describe alternatives you've considered

Putting this card inside a button-card to template the service_data param, but I haven't been able to return a dict that is taken by this card.

Using lovelace-gen seem too much for me just for this card.

Additional context

No response

@luixal
Copy link
Author

luixal commented May 17, 2023

Just got it working putting this card inside a button-card card and using js templates, like this:

service_data: |
  [[[
    if (entity.state == 'on') {
      return {
        entity_id: entity.entity_id
      }
    } else {
      return {
        entity_id: entity.entity_id,
        time: '00:00:10'
      }
    }
]]]

I still think state_actions would be a great addition to this card :)

@Masterz69
Copy link

Waiting too. Feature was planned to v2.1.0 almost year ago (see #105).
Hope it will be implemented.

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