core icon indicating copy to clipboard operation
core copied to clipboard

Blueprint trigger on target fails

Open swifty99 opened this issue 3 years ago • 9 comments

The problem

entities are treated differently if defined as target or as entity.

with these definitions

  input:
    target_light:
      name: Light
      description: The light to operate, 
      selector:
        target:
          entity:
            domain: light

    entity_lights:
      name: Light
      description: The light to operate, 
      selector:
        entity:
          domain: light

the trigger:

trigger:
- platform: state
  entity_id: !input 'entity_lights'

works however neither of these:

trigger:
- platform: state
  entity_id: !input 'target_light'

or

trigger:
- platform: state
  target: !input 'target_light'

The error is something like this:

`Blueprint Use RGBW as CT Light (dev) generated invalid automation with inputs OrderedDict([('rgbw_2_ct_requested_input', ...
, ('entity_lights', 'light.testlight1')]): Entity entity_id is neither a valid entity ID nor a valid UUID for dictionary value @ data['entity_id']. Got None`

which makes somewhat sense as:

variables:
  target_light: !input 'target_light'
  entity_lights: !input 'entity_lights'

In my only way to debug via MQTT publish, to "see" content of variablse

 action
     - service: mqtt.publish
          data:
            topic: '{{rgbw_2_ct_mqtt_topic}}'
            payload_template: >
              great:  {{rgbw_2_ct_mqtt_topic}}
              {{"\n"}}entity_lights: {{entity_lights}}
              {{"\n"}}target_light: {{target_light}}

renders as

entity_lights: light.testlight1 
target_light: {'entity_id': 'light.testlight1'} 

they are not treated same internally. I think it should not make a difference and the target should contain the entity id only.

Please consider, in the sake of 2022 making homeassistand easier for everyone

  • treat target an entity inputs the same way
  • offer a way to debug blueprints
  • update blueprint information.

What version of Home Assistant Core has the issue?

2021.12.7

What was the last working version of Home Assistant Core?

2021.12.7

What type of installation are you running?

Home Assistant OS

Integration causing the issue

blueprint

Link to integration documentation on our website

No response

Example YAML snippet

blueprint:
  name: Use RGBW as CT Light (dev)
  source_url: https://gist.github.com/swifty99/e29e523002bbe6c0533edda9257dbea1
  description: >
     Control a RGBW Light as a CT controlled light with good color accuracy an wide color temperature spectrum.
     Make sure you proved a calibration value for each CT datapoint.
  domain: automation
  input:
    rgbw_2_ct_target_ct:
      name: Calibrated CT values
      description: >
         Use the color temperature values you calibrated the light against. Five values recommende, three minimum. 
         Specify as List: eg [1900, 2100, 2600, 5500, 10000]. The calibration point in the middle shoould be native white of your rgbW
         Values must be ascending.
      selector:
        object:
      default: [1900, 2100, 2600, 5500, 10000]
    rgbw_2_red_calibration:
      name: Calibrated Values for red channel
      description: >
         As CT goes from low to high, the red channel goes from a high value to a low value. At base CT of native White it should be zero. 
         Values to the right should be zero, too. A good starting ppoint may be [100, 100, 0, 0, 0], all LED calibration values 0..100
      selector:
        object:
      default: [100, 100, 0, 0, 0]
    rgbw_2_green_calibration:
      name: Calibrated Values for green channel
      description: >
         Green is special. It is neede at high an low CT, however probably not while at base CT of W. Adjust to your liking. 
         A good starting ppoint may be [50, 50, 0, 77, 88]
      selector:
        object:
      default: [50, 50, 0, 77, 88] 
    rgbw_2_blue_calibration:
      name: Calibrated Values for blue channel
      description: >
         Higher values at higher CT. Schould be 0 at and below base CT. Max at highest CT, maybe like this [100, 0, 0, 89, 100]
      selector:
        object:
      default: [0, 0, 0, 89, 100] 
    rgbw_2_white_calibration:
      name: Calibrated Values for white channel
      description: >
         This is the base white. Good color rendition depends on this. At base CT of this light it should be maxed. Do not set to 0 to achieve good CRI 
         Starting point  [30, 70, 100, 72, 60]
      selector:
        object:
      default: [30, 70, 100, 72, 60] 
    rgbw_2_ct_requested_input:
      name: Color Tempereture target
      description: The RGBW light will be set to this color temperature. Automation will trigger on this change
      selector:
        entity:
          domain: input_number  
    rgbw_2_ct_mqtt_topic:
      name: MQTT debug topic
      description: Optional. Outputs debug information and the calibrated values.
      default: ""
      selector:
        text:
    target_light:
      name: One! RGBW Light
      description: The light to operate, must be RGBW one. Automation stucks if more than one light is provided. They should have individual calibration anyaway.
      selector:
        target:
          entity:
            domain: light
    entity_lights:
      name: Lights
      description: 'The light(s) you want to auto reset to your default settings when
        they turn on. For more than one, add a comma and no spaces between the full
        entity names. Example: light.lamp_left,light.lamp_right'
      selector:
        entity:
          domain: light


variables:
  rgbw_2_ct_requested_input: !input 'rgbw_2_ct_requested_input'
  rgbw_2_ct_target_ct: !input 'rgbw_2_ct_target_ct'
  rgbw_2_red_calibration: !input 'rgbw_2_red_calibration'
  rgbw_2_green_calibration: !input 'rgbw_2_green_calibration'
  rgbw_2_blue_calibration: !input 'rgbw_2_blue_calibration'
  rgbw_2_white_calibration: !input 'rgbw_2_white_calibration'
  rgbw_2_ct_debugmessage: 'looking good'
  rgbw_2_ct_mqtt_topic: !input 'rgbw_2_ct_mqtt_topic'
  target_light: !input 'target_light'
  ltarget_light_ID: '{{target_light.entity_id}}'
  rgbw_my: '{{state_attr(target_light.entity_id, ''supported_color_modes'')}}'
  rqgw_colormod_accept: '[''rgbw'']'
  target_light_brightness: '{{state_attr(target_light.entity_id, ''brightness'')}}'
  blueprint_version: '2022-01-1'
  entity_lights: !input 'entity_lights'

trigger:
- platform: state
  entity_id: !input 'target_light'

# rgbw_my == rqgw_colormod_accept
action:
- alias: "check input data, check light type"
  choose:
  - conditions: >
      {{(( ((rgbw_2_ct_target_ct | length ) | int(0) ) 
      == ((rgbw_2_red_calibration | length) | int(0) )
      == ((rgbw_2_blue_calibration | length) | int(0) )
      == ((rgbw_2_white_calibration | length) | int(0) )
      == ((rgbw_2_green_calibration | length) | int(0) ) 
        ))}}
    sequence:        
    - alias: "Calculate color data"
      variables:
        mredList: '[{% for value in rgbw_2_ct_target_ct -%} {{(10**6 / value)|round }} {%- if not loop.last %},{% endif %}{%- endfor %}]'
        mred_target: '{{10**6 / (states(rgbw_2_ct_requested_input)|float) }}'
        mred_index: >
          {% set mred_index = namespace(index=0) -%}   
          {%- if mred_target > mredList[0] -%}  
            0     
          {%- elif mred_target <= mredList[(mredList |length)-1] -%}
              {{(mredList|length)-2 }}   
          {%- else -%}  
            {% for value in mredList -%} 
              {% if value > mred_target %} {%- set mred_index.index = loop.index -1 %}  {% endif %}
            {%- endfor %} 
            {{ mred_index.index  }} 
          {%- endif %}
        mred_offset: >
          {% if mred_target > mredList[0] %} 
            0   
          {%- elif mred_target <= mredList[(mredList |length)-1] %} 
            1   
          {%- else -%}  
            {{ (mred_target - (mredList[mred_index])) /(mredList[mred_index +1] - mredList[mred_index]) }}   
          {%- endif %}
        r_value: >
          {{ rgbw_2_red_calibration[mred_index] + (rgbw_2_red_calibration[mred_index +1] -rgbw_2_red_calibration[mred_index ]) *  mred_offset }}
        g_value: >
          {{ rgbw_2_green_calibration[mred_index] + (rgbw_2_green_calibration[mred_index +1] -rgbw_2_green_calibration[mred_index ]) * mred_offset }}
        b_value: >
          {{ rgbw_2_blue_calibration[mred_index] + (rgbw_2_blue_calibration[mred_index +1] -rgbw_2_blue_calibration[mred_index ]) * mred_offset }}
        w_value: >
          {{ rgbw_2_white_calibration[mred_index] + (rgbw_2_white_calibration[mred_index +1] -rgbw_2_white_calibration[mred_index ]) *  mred_offset }}
    
    - alias: "Apply color data to light, "
      service: light.turn_on  
      data:
        rgbw_color:
        - '{{ r_value | float(0) * 2.55}}'
        - '{{ g_value | float(0) * 2.55}}'
        - '{{ b_value | float(0) * 2.55}}'
        - '{{ w_value | float(0) * 2.55}}'
          
      target: !input target_light   
    
    - alias: "optional mqtt debug"
      choose:
      - conditions:
          '{{(rgbw_2_ct_mqtt_topic|length) > 5}}'
        sequence:
        - service: mqtt.publish
          data:
            topic: '{{rgbw_2_ct_mqtt_topic}}'
            payload_template: >
              great:  {{rgbw_2_ct_mqtt_topic}}
              {{"\n"}}entity_lights: {{entity_lights}}
              {{"\n"}}target_light: {{target_light}}
              {{"\n"}}input trigger: {{rgbw_2_ct_requested_input}}
              {{"\n"}}old bright: {{target_light_brightness}}
              {{"\n"}}mredList: [{% for value in rgbw_2_ct_target_ct -%} {{(10**6 / value)|round }} {%- if not loop.last %},{% endif %}{%- endfor %}]
              {{"\n"}}mred_target: {{mred_target}}
              {{"\n"}}mred_index: {{mred_index}}
              {{"\n"}}mred_offset: {{mred_offset }}
              {{"\n"}}RGBW: {{r_value}}, {{g_value}}, {{b_value}}, {{w_value}}
            retain: false


      
  default:
    - alias: "optional mqtt debug"
      choose:
      - conditions:
          '{{(rgbw_2_ct_mqtt_topic|length) > 5}}'
        sequence:
        - service: mqtt.publish
          data:
            topic: '{{rgbw_2_ct_mqtt_topic}}'
            payload_template: >
              Calibration data points need equal data size, all need to have {{rgbw_2_ct_target_ct| length}} values as CT data
              {{"\n"}}red has {{(rgbw_2_red_calibration|length)}} values
              {{"\n"}}green has {{(rgbw_2_green_calibration|length)}} values
              {{"\n"}}blue has {{(rgbw_2_blue_calibration|length)}} values
              {{"\n"}}white has {{(rgbw_2_white_calibration|length)}} values
              {{"\n"}}or color mode of light is not RGBW, is {{rgbw_my}} not {{rqgw_colormod_accept}}
            retain: false
      default:

mode: single
max_exceeded: silent

Anything in the logs that might be useful for us?

No response

Additional information

Blueprints are great, however I spent way, way, waaaay too much time debugging.

swifty99 avatar Jan 23 '22 18:01 swifty99

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (blueprint) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

Hm, I do not believe this is fixed or the correct way to handle the trigger. Somone disagrees?

swifty99 avatar Mar 02 '22 19:03 swifty99

Agree, this is really confusing. And no it's not fixed.

elupus avatar Apr 06 '24 19:04 elupus

The problem seems to be following:

When using the selector without target, the input values becomes e.g. light.somelight, therefore, it can be used as the triggers entity_id.

When using the selector with target, the value becomes a dict with value {entity_id: light.somelight}.

Therefore, one would need to specify the entity_id attribute when specifying the trigger, something like this:

trigger:
- platform: state
  entity_id: !input myinput.entity_id # <- not possible?

Unfortunately, I don't think there is a way to do that?

marcoschulte avatar Apr 17 '24 09:04 marcoschulte

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Still valid

elupus avatar Jul 16 '24 10:07 elupus

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

not so fast stalebot!

swifty99 avatar Oct 14 '24 18:10 swifty99

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Not so fast stalebot!

XHale84 avatar Jan 13 '25 18:01 XHale84

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

We still need this!

XHale84 avatar Apr 14 '25 08:04 XHale84

Oh hi there 👋

Looking through the older issues and came across this one.

This is, however, not a bug. Triggers & conditions do not support targets. Targets are not the same as entity_ids.

Thus this:

trigger:
- platform: state
  entity_id: !input 'target_light'

Is, correctly, not working.

As this is intended (they are different things), I'll go ahead and close this bug report.

../Frenck

frenck avatar Apr 15 '25 20:04 frenck

@frenck

thx for clarifying. However closing this issue without further action is maybe not the right thing.

Developing blueprints is a nightmare. At least it was, and it should not be. It took me a severe amount of time to find out. According to the comments I am not alone.

So please, please. update the docs, give help to debug blueprints or whatever. It was so frustrating I gave up almost. It should not be that way.

Cheers Jan

swifty99 avatar Apr 16 '25 18:04 swifty99

Fully agree, i spent a long time trying to figure this out since no reasonable error is generated.

elupus avatar Apr 16 '25 18:04 elupus