'expected float for disctionary value' error when setting light brightness (solved)

I’ve seen this reported elsewhere but cannot figure out how to solve this. I am trying to set a light’s brightness to a fraction of anothers…

This is the code I am trying to get working taken from a ‘turn light on’ automation action, which throws "malformed: expected float at dictionary value @data ‘brightness_pct’

type: turn_on
device_id: 16fedb8a181eb726acdf73c5df765452
entity_id: 79d2f918b2f866102579e10493bcfac7
domain: light
brightness_pct: '{{  ((state_attr('light.rgbw_dimmer_5','brightness') /  5.1 | float) | round) }}'

This code returns a value with no decimles in a 1-100 range as normally is accepted by this input field. For example at the time of writing, when pasting this line into the templat editor in developer tools, I get 11

I have tried modifying the automation action such that this has ’ ’ around it, as well as " ", neither helps.

I have tried this as well with no luck:

{{ (state_attr(‘light.rgbw_dimmer_5’,‘brightness’) / 5.1 | int) }}

I am pretty sure you can’t use templates in a Device action. Device triggers/conditions/actions are for very simple use cases. If you switch to the visual editor you’ll see that the UI will not even allow you to enter any characters for brightness except for numbers. For more advanced cases, use a normal service call instead, and prefer entities over devices for more reliability (device IDs can change if the devices is removed and replaced).

service: light.turn_on
data:
  brightness_pct: "{{ (state_attr('light.rgbw_dimmer_5','brightness') /  5.1 | float) | round }}"
target:
  entity_id: light.dimmer_switch
1 Like

Correct.

2 Likes

This did the trick after some playing around. At first it did not seem to throw an error, it just would not save. I kept refreshing and the value would just be null. Eventually after changing to double " " it seemed to like that and will run the automation now. Thank you! And sorry for not trying that as a service.

I fixed the example, didn’t notice that the first time.