EPMatt / awesome-ha-blueprints

A curated collection of automation blueprints for Home Assistant.
https://epmatt.github.io/awesome-ha-blueprints
GNU General Public License v3.0
841 stars 248 forks source link

Bug - error after upgrade to ja 2022.07 #362

Open Delta1977 opened 2 years ago

Delta1977 commented 2 years ago

Blueprint name

Hook-light

Home Assistant Core Version

2022.07

Home Assistant Installation Type

Home Assistant Operating System

Description

Logger: homeassistant.components.automation.hook_light_schlafzimmer Source: components/automation/init.py:525 Integration: Automatisierung (documentation, issues) First occurred: 21:53:33 (6 occurrences) Last logged: 21:58:40

Error while executing automation automation.hook_light_schlafzimmer: Error rendering data template: ValueError: Template error: int got invalid input 'None' when rendering template '{{ [state_attr(light,"color_temp")|int - 50, 1]|max }}' but no default was specified Error while executing automation automation.hook_light_schlafzimmer: Error rendering data template: ValueError: Template error: int got invalid input 'None' when rendering template '{{ state_attr(light,"color_temp")|int + 50 }}' but no default was specified

Automation YAML config

alias: Hook - Light Schlafzimmer
description: ''
use_blueprint:
  path: EPMatt/light.yaml
  input:
    light_color_mode: Auto
    controller_device: 36ed4a3945985b599e82e025eca8af66
    controller_entity: sensor.ikea_taster_schlafzimmer_action
    controller_model: IKEA E2001/E2002 STYRBAR Remote control
    light: light.ikea_lampe_schlafzimmer
    smooth_power_off: true

To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Trigger the automation '....'
  4. See error

Expected behavior

.

Actual Behaviour

.

Additional Details

Screenshots

No response

Additional context

No response

YAMLcase commented 2 years ago

I am seeing this same error. More info perhaps to help troubleshoot: I have the following:

The light takes either color_temp, color_hs, or color_xy. I have been able to demonstrate when the light's current color_mode is color_xy and the hook's Light Color Mode is set to "Color Temperature", sending an action to color_up or color_down will result in the failure. Any other combination will not show the error.

I have narrowed it down to this block, but am getting into details I'm not understanding yet:

action:
  - choose:
      - conditions: '{{ action == color_up and light_color_mode_id != "none" }}'
        sequence:
          choose:
            - conditions: '{{ light_color_mode_id == "color_temp" }}'
              sequence:
                - service: light.turn_on
                  data:
                    color_temp: '{{ state_attr(light,"color_temp")|int + 50 }}'
                    transition: 0.25
                  entity_id: !input light
YAMLcase commented 2 years ago

@Delta1977 with my issue I discovered the light does not provide color_temp: <int> when the state was last set with a color.

diff --git temp hs
supported_color_modes:
 friendly_name: office/lights/main02
 supported_features: 63
 color:
  x: 0.348
  'y': 0.368
last_seen: '2022-09-04T14:56:53.694Z'
 level_config:
   on_level: previous
linkquality: 102
 update:
   state: idle
 update_available: false
-color_mode: color_temp
+color_mode: xy
 brightness: 255
 hs_color:
  - 58.421
  - 14.902
 rgb_color:
   - 255
  - 254
  - 217
 xy_color:
  - 0.482
  - 0.38
-color_temp: 316

Given 'state_attr(light,"color_temp")... no default was specified, I'm on the hunt on how to either give a default value for this bit or add some conditionals. I'm just learning the Home Assistant templating syntax, so any pointers would be greatly appreciated @EPMatt @kingy444

YAMLcase commented 2 years ago

update: I think I solved my issue at least. I'm basically calculating a good color_temp based on current brightness and using that if color_temp is missing. I think it would be a good feature request if we could supply a default value for state_attr(), but this will get me by

      - conditions: '{{ action == color_up and light_color_mode_id != "none" }}'
        sequence:
          choose:
            - conditions: '{{ light_color_mode_id == "color_temp" }}'
              sequence:
                - service: light.turn_on
                  data:
                    color_temp: >-
                      {%- if state_attr(light,"color_temp") != None -%}
                        {{ state_attr(light,"color_temp")|int + 50 }}
                      {%- else -%}
                        {{ 500 - state_attr(light,"brightness")|int}}
                      {%- endif -%}
                    transition: 0.25
                  entity_id: !input light