Automation syntax and proper use of commands

I’m attempting to create a generic binary switch blueprint based on sensor value, or rather an attribute state(?) which should toggle/set an object on or off depending on state.

It’s my first go at this and I’m struggling :wink:
Input appreciated on obvious faults.

The sensor in my case has an attribute called ‘price_level’ which can be
Very_exensive
Expensive
Normal
Cheap
Very_cheap

Ideally I want the blueprint to include a checkbox/whatnot to chose which states will set object to off (the “else on”)

blueprint:
 name: Binary switch based on electricity price
 description: Toggle an object ON/OFF depending on Tibbers Price levels
 domain: automation
 input:
  sensor:
   name: PriceSensor
   description: This sensor will be used
   selector:
    entity:
     domain: sensor
# Grab sensor with current price
    target_light:
     name: Lights
     description: Object to toggle with Price Sensor
     selector:
      entity:
       domain: light
#
trigger:
 - platform: state
   entity_id: !input PriceSensor
#
action:
 - service: >
    {% if trigger.to_state.state == "EXPENSIVE" OR "VERY_EXPENSIVE %}
      light.turn_off
    {% else %}
      light.turn_on
    {% endif %}
# If price is EXPENSIVE or VERY_EXPENSIVE - then toggle off.
# If price is NORMAL, CHEAP or VERY_CHEAP then toggle on
#
   target: !input target_light

Why are you making a blueprint? are you going to re-use the same automation over and over again or is it just a one-off automation?

Have you tried to just get the automation part running first? and then create a blueprint from that working automation if needed?

Two reasons:
reuse for various objects
Share the functionality

I’ll have a go at the simpler approach :slight_smile:

1 Like

These are the available selectors and I don’t see one that does what you want. I believe the select selector may be what you want