How to use IF in blueprints

I would like todo an IF formula based on my select options (jc_control:)
Cant figure it out. thanks for the help

blueprint:
  name: ScriptLightON live
  
  description: Turn on lights Living
  domain: script
  author: JC Dreyfus
  #icon: mdi:lightbulb
  input:
    light_target:
      name: Light #!input light_target
      selector:
        entity:
          domain:
            - light

    jc_control:
      name: Use The Light Control Options
      description: Light Control Options
      default: []
      selector:
        select:
          multiple: false
          options:
            - label: Use Only Brightness
              value: use_brightness
            - label: Use Color Temperature Kelvin
              value: use_color_tempetature  
            - label: Use Color Name
              value: use_color_name
            - label: Use Color RGB
              value: use_color_rgb  
            - label: Use Color HS
              value: use_color_hs

    light_brightness:
      name: Brightness
      description: The brightness setting for the lights when they are turned ON.
      default: 35
      selector:
        number:
          min: 1
          max: 100
          mode: box
          step: 1
          unit_of_measurement: '%'

    light_color_kelvin:
      name: Color Temperature 
      description: in Kelvin
      default: 4600
      selector:
        number:
          min: 2000
          max: 8000
          mode: box
          step: 100
          unit_of_measurement: 'kelvin'

    light_color:
      name: Color Name
      description: The Color Name
      default: 
      selector:
        text:

    light_color_rgb:
      name: Color RGB
      description: The colour temperature setting for the lights when they are turned ON.
      default: 
      selector:
        color_rgb:

    light_color_hs:
      name: Color HS
      description: The colour temperature setting for the lights when they are turned ON.
      default: 
      selector:
        object:

#variables:
#  light_target: !input light_target
#  use_brightness: !input use_brightness



alias: "Lights On"
sequence: 

  - if:
      - condition: state
        entity_id: !input jc_control
        state: use_brightness
    then:
      - data:
          brightness_pct: !input light_brightness
          color_temp: !input light_color_kelvin
        continue_on_error: true
        target:
          entity_id: !input light_target
        action: light.turn_on

  
mode: restart
max_exceeded: silent
icon: mdi:lightbulb

Hi jcd420,

TBH I have mostly abandoned the If statements stuff and use the choose statements instead, I would suggest that method…
Script Syntax - Home Assistant.

I think the issue is you are treating jc_control like an entity, but it’s just a string (it’s not an input_select if that’s what your thinking).

I think you can use a template condition to check the value like below. I think in order To use jc_control in a template, you have to store it in a variable.

Fair warning: I’m new at this.

variables:
  jc_control: !input jc_control
#  light_target: !input light_target
#  use_brightness: !input use_brightness

alias: "Lights On"
sequence:
  - if:
      - condition: template
        value_template: '{{jc_control == "use_brightness"}}'
    then:
      - data:
          brightness_pct: !input light_brightness
          color_temp: !input light_color_kelvin
        continue_on_error: true
        target:
          entity_id: !input light_target
        action: light.turn_on

mode: restart
max_exceeded: silent

im having issiu using choice also. what am I doing wrong?

also I get this erro:

Message malformed: extra keys not allowed @ data[‘actions’]

blueprint:
  name: ScriptLightON live2b
  
  description: Turn on lights Living
  domain: script
  author: JC Dreyfus
  #icon: mdi:lightbulb
  input:
    light_target:
      name: Light #!input light_target
      selector:
        entity:
          domain:
            - light

    jc_control:
      name: Use The Light Control Options
      description: Light Control Options
      default: []
      selector:
        select:
          multiple: false
          options:
            - label: 'Use Only Brightness'
              value: 'use_brightness'
            - label: Use Color Temperature Kelvin
              value: use_color_tempetature  
            - label: Use Color Name
              value: use_color_name
            - label: Use Color RGB
              value: use_color_rgb  
            - label: Use Color HS
              value: use_color_hs

    light_brightness:
      name: Brightness
      description: The brightness setting for the lights when they are turned ON.
      default: 35
      selector:
        number:
          min: 1
          max: 100
          mode: box
          step: 1
          unit_of_measurement: '%'

    light_color_kelvin:
      name: Color Temperature 
      description: in Kelvin
      default: 4600
      selector:
        number:
          min: 2000
          max: 8000
          mode: box
          step: 100
          unit_of_measurement: 'kelvin'

    light_color:
      name: Color Name
      description: The Color Name
      default: 
      selector:
        text:

    light_color_rgb:
      name: Color RGB
      description: The colour temperature setting for the lights when they are turned ON.
      default: 
      selector:
        color_rgb:

    light_color_hs:
      name: Color HS
      description: The colour temperature setting for the lights when they are turned ON.
      default: 
      selector:
        object:

actions:
  - choose:
      - conditions:
          - condition: "{{ states(jc_control)== 'use_brightness' }}"
        sequence:
          - action: light.turn_on
            data:
              brightness: 100
            target:
              entity_id: !input light_target
  

mode: restart
max_exceeded: silent
icon: mdi:lightbulb

on the IF I get this erro:

Message malformed: Unexpected value for condition: ‘{{ states(jc_control) == ‘use_brightness’ }}’. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data[‘sequence’][0][‘if’][0]

also did like link sent. and still got erros:

Message malformed: extra keys not allowed @ data[‘actions’]

blueprint:
  name: ScriptLightON live2b
  
  description: Turn on lights Living
  domain: script
  author: JC Dreyfus
  #icon: mdi:lightbulb
  input:
    light_target:
      name: Light #!input light_target
      selector:
        entity:
          domain:
            - light

    jc_control:
      name: Use The Light Control Options
      description: Light Control Options
      default: []
      selector:
        select:
          multiple: false
          options:
            - label: 'Use Only Brightness'
              value: 'use_brightness'
            - label: Use Color Temperature Kelvin
              value: use_color_tempetature  
            - label: Use Color Name
              value: use_color_name
            - label: Use Color RGB
              value: use_color_rgb  
            - label: Use Color HS
              value: use_color_hs

    light_brightness:
      name: Brightness
      description: The brightness setting for the lights when they are turned ON.
      default: 35
      selector:
        number:
          min: 1
          max: 100
          mode: box
          step: 1
          unit_of_measurement: '%'

    light_color_kelvin:
      name: Color Temperature 
      description: in Kelvin
      default: 4600
      selector:
        number:
          min: 2000
          max: 8000
          mode: box
          step: 100
          unit_of_measurement: 'kelvin'

    light_color:
      name: Color Name
      description: The Color Name
      default: 
      selector:
        text:

    light_color_rgb:
      name: Color RGB
      description: The colour temperature setting for the lights when they are turned ON.
      default: 
      selector:
        color_rgb:

    light_color_hs:
      name: Color HS
      description: The colour temperature setting for the lights when they are turned ON.
      default: 
      selector:
        object:

actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.bednightstand
            state: "on"      
#          - condition: "{{ states(jc_control)== 'use_brightness' }}"
        sequence:
          - action: light.turn_on
            data:
              brightness: 100
            target:
              entity_id: !input light_target
  

mode: restart
max_exceeded: silent
icon: mdi:lightbulb

I think the problem is that you are using states(jc_control), when it should just be jc_control like this:

'{{jc_control == "use_brightness"}}'

I think you have to include the variable definition for jc_control as well:

variables:
  jc_control: !input jc_control
1 Like

For you choose statement example, I would guess the issue is that you need to replace

actions:

with

sequence:

I think you use actions with automation blueprints and sequence with script blueprints.

1 Like

(for a couple of more weeks, anyway) hint hint…

1 Like

that was it. now it look like my formula is wrong. Do you have any idea what im doing wrong?

"{{ states(jc_control)== use_brightness }}"

I tried:

          - condition: template
            value_template: "{{ states(jc_control)== use_brightness }}"

or

          - condition: template
            value_template: "{{ states(jc_control)== 'use_brightness' }}"

also

       - condition: state
         entity_id: !input jc_control
         state: use_brightness

also

- condition: "{{ states(jc_control)== 'use_brightness' }}"

If you read the entire thread here, a couple of people told you how to fix that I believe.
jc_control is a string, it doesn’t have a state.
If you want it in a template, you need to use a variable statement.
Blueprints: Get your !input value into a template.

1 Like

Wow, thank you so much. I have been looking for a simple example for weeks.

1 Like