Hello All!
I’m really banging my head against a wall here. I’ve reduced the list of % set… commands to a single line:
action:
- variables:
screenBrightness: {{ ((trigger.to_state.state * 245) / 80) + 10 }}
or
action:
- variables:
screenBrightness:
{{ ((trigger.to_state.state * 245) / 80) + 10 }}
The line on the editor’s left hand side is blue (i.e. the code parses correctly) and I can hit the Save button. But after exiting and re-entering the yaml-editor, the code always reverts to:
action:
- variables:
screenBrightness:
"[object Object]": null
Please help! I’m losing my mind… :-/
EDIT:
Without the math, this code:
alias: W32 adjust screen brightness
description: W32 adjust screen brightness
trigger:
- platform: state
entity_id: sensor.zoe_lux
not_to:
- unknown
- unavailable
condition: []
action:
- alias: "Set lux value to variable"
variables:
screenBrightness: "{{ states('sensor.zoe_lux') }}"
- service: mqtt.publish
data:
qos: 0
retain: false
topic: hasp/w32screen1/command
payload: "backlight {{ screenBrightness }}"
mode: single
… pushes the current lux value of the sensor to the screen’s backlight. Now, I need to scale it somehow…
Using the Template tab in the Developer Tools, I got this code to work:
{% if (((states('sensor.zoe_lux')|float * 245) / 80) + 10) > 255 %}
screenBrightness: "255"
{% elif (((states('sensor.zoe_lux')|float * 245) / 80) + 10) < 10 %}
screenBrightness: "10"
{% else %}
screenBrightness: "{{ ((states('sensor.zoe_lux')|float * 245) / 80) + 10 }}"
{% endif %}
In my automation I tried:
action:
- alias: "Set lux value to variable"
variables_templates: >-
{% if (((states('sensor.zoe_lux')|float * 245) / 80) + 10) > 255 %}
screenBrightness: "255"
{% elif (((states('sensor.zoe_lux')|float * 245) / 80) + 10) < 10 %}
screenBrightness: "10"
{% else %}
screenBrightness: "{{ ((states('sensor.zoe_lux')|float * 245) / 80) + 10 }}"
{% endif %}
But am met with the error message: Message malformed: Unable to determine action @ data['action'][0]
… I feel like I’m close. Any ideas?