#Script with parameter checking via value_template

1 messages · Page 1 of 1 (latest)

quartz bison
#

I have got an issue with a script where I want to do 'things' based on a given parameter. The action is quite plain and simple. Can anybody help me with the condition? Error:
The definition of the script is as follows:

  alias: Switch the valve on/off
  icon: mdi:text
  description: This script switches the valve after hitting the button in lovelace
  fields:
    valve_action:
      description: "The action to be performed on the valve"
      advanced: false
      required: true
      example: "off"
      default: "onoff"
  mode: queued
  sequence:
    - conditions:
        - condition:
          value_template: "{{ valve_action == 'onoff' }}"
      sequence:
        - service: switch.turn_on
          target:
            entity_id: switch.l2_bathroom01a_ssr_01
          data: {}```
white dune
#

seems like maybe you wanted to post an error message, but I don't see it?

south karma
#

you have condition: and you need condition: template

oak inlet
#

Hey @quartz bison in HA scripts, conditions should use condition type rather than value_template directly.

#

just like template for a templated condition

quartz bison
south karma
#

the syntax is also wrong there. you have an extra "sequence", and it looks like you really intended to use an if, which you don't actually need here

#

the whole thing is just kinda confused

#
lovelace_l2_bathroom01a_ssr_01:
  alias: Switch the valve on/off
  icon: mdi:text
  description: This script switches the valve after hitting the button in lovelace
  fields:
    valve_action:
      description: "The action to be performed on the valve"
      advanced: false
      required: true
      example: "off"
      default: "onoff"
  mode: queued
  sequence:
    - condition: template
      value_template: "{{ valve_action == 'onoff' }}"
    - service: switch.turn_on
      target:
        entity_id: switch.l2_bathroom01a_ssr_01
      data: {}
oak inlet
#
- condition: template
      value_template: "{{ valve_action == 'onoff' }}"
south karma
#

that indentation is off

quartz bison
# south karma the syntax is also wrong there. you have an extra "sequence", and it looks like...

I have two use cases based on the parameter valve_action. I understood I need 2 times -conditions and sequence: therefor:

    - conditions:
        - condition: "{{ valve_action == 'onoff' }}"
      sequence:
        - service: switch.turn_on
          target:
            entity_id: switch.l2_bathroom01a_ssr_01
          data: {}
        - delay: 00:00:10
        - service: switch.turn_off
          target:
            entity_id: switch.l2_bathroom01a_ssr_01
          data: {}
    - conditions:
        - condition: "{{ valve_action == 'off' }}"
      sequence:
        - service: switch.turn_off
          target:
            entity_id: switch.l2_bathroom01a_ssr_01
          data: {}```
south karma
#

you keep using conditions: with just a single condition:

#

seems like you really wanted choose:

#

or perhaps if/then/else