Hello!
I’m currently experimenting with Home Assistant, after using openHab for a number of years.
I’m getting an “Expected float for dictionary values @ data[‘brightness_pct’” error, when trying to use some template sensor data to set the brightness of a Phillips Hue lightbulb.
It seems that YAML has a bit of a learning curve, so I’m hoping someone can help me out. It’s probably something simple, but I’ve been wracking my brain over it all evening!
Everything is showing up as expected when I display the entities on the dashboard.
Thanks!
configuration.yaml
sensor:
- platform: template
sensors:
sun_elevation:
unique_id: "sun_elevation"
friendly_name: "Sun Elevation"
unit_of_measurement: "°"
value_template: "{{state_attr('sun.sun', 'elevation') }}"
circadian_brightness:
unique_id: "circadian_brightness"
friendly_name: "Circadian Brightness"
unit_of_measurement: "%"
value_template: >
{% set max = 0 | float %}
{% set min = -10 | float %}
{% set current = state_attr('sun.sun', 'elevation') | float %}
{% set percent = ((current-min)/(max-min))*100 | float %}
{% if percent > 100 %}
100
{% elif percent < 1 %}
1
{% else %}
{{ percent | float }}
{% endif %}
Automation
alias: "Hue Brightness "
description: ""
trigger:
- platform: state
entity_id:
- sensor.circadian_brightness
condition:
- condition: state
entity_id: light.bedroom
state: "on"
enabled: true
action:
- type: turn_on
device_id: eaca0cd93a71d68436e51c947fe15fba
entity_id: light.bedroom
domain: light
brightness_pct: "{{ states('sensor.circadian_brightness') | float }}"
mode: single