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

Test variable in automation action condition #12

Open
MartinAKu opened this issue Dec 26, 2018 · 3 comments
Open

Test variable in automation action condition #12

MartinAKu opened this issue Dec 26, 2018 · 3 comments

Comments

@MartinAKu
Copy link

Hi,

I try to do a conditional action within an automation based on the (integer) value of a variable. This is the code:
- alias: sensor2 initial_state: 'on' trigger: - platform: state entity_id: binary_sensor.stair2 action: - service: automation.turn_off entity_id: automation.sensor2 - service: automation.turn_on entity_id: automation.sensorTimeout - service: variable.set_variable data: variable: stair_state value_template: '{{ 3 if (variable.state | int) == 1 else 2 }}' - condition: template value_template: '{{ (states.variable.stair_state.state | int) == 3 }}' - service: script.turn_on entity_id: script.stair_up

I'm sure the variable stair_state = 3 but the script 'stair_up' isn't called. What can be wrong?

@MartinAKu
Copy link
Author

Sorry for the non-formatted code. Below the formatted code.

- alias: sensor2
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.stair2
  action:
    - service: automation.turn_off
      entity_id: automation.sensor2
    - service: automation.turn_on
      entity_id: automation.sensorTimeout
    - service: variable.set_variable
      data:
        variable: stair_state
        value_template: '{{ 3 if (variable.state | int) == 1 else 2 }}'
    - condition: template
        value_template: '{{ (states.variable.stair_state.state | int) == 3 }}'
    - service: script.turn_on
      entity_id: script.stair_up

@OleksandrBerchenko
Copy link

Does {{ 3 if (states.variable.stair_state.state | int) == 1 else 2 }} work?

@MartinAKu
Copy link
Author

Yes, this line works.

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