i hav ean error in logs: Invalid data for call_service at pos 1: Service light.turn_on
data: entity_id: light.lenta_gostinaia does not match format ., and my automation does not work.
Help me please.
It’s the data_template that continues to do all the heavy-lifting. I’d like to draw your attention to the following situation.
Assume the light is on.
Both tests are false but there’s no else to handle this situation therefore brightness_pct will be set to no value at all.
Same situation applies to rgb_color.
data_template:
brightness_pct: >
{% set ts = as_timestamp(states.sun.sun.attributes.next_rising) %}
{% set light = is_state('light.lenta_gostinaia', 'off') %}
{% if ts -86400 < as_timestamp(now()) and light -%}10
{% elif ts -86400 > as_timestamp(now()) and light -%}50
{% endif %}
I realize the light will be turned off so maybe it doesn’t matter. I’m just not sure how Home Assistant will handle this situation where the template returns no value to assign to the option.
The idea was to dim lights at evening and night.
Now, with @walrus_parka script i have an error with variables. found character ‘%’ that cannot start any token
in “/home/homeassistant/.homeassistant/automations.yaml”, line 312, column 6
This line points to
{% set ts = as_timestamp(states.sun.sun.attributes.next_rising) %}
This was my fault. This lines must be indented with 2 spaces.
But now i have one more error 2019-04-13 16:22:48 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.gostinaia_knopka_lenta. Invalid data for call_service at pos 1: extra keys not allowed @ data[‘rgb_color’]
I would suggest what @123 mentioned. Regardless of the time we are toggling the light.
Adding an else to the brightness_pct for any other time the button is pressed.
Replaced the last elif with else to the rgb_color since it is already full white. If that is not what is desired, add an else with whatever rgb color is needed.
- service_template: light.toggle
entity_id: light.lenta_gostinaia
data_template:
brightness_pct: >
{% set ts = as_timestamp(states.sun.sun.attributes.next_rising) %}
{% set light = is_state('light.lenta_gostinaia', 'off') %}
{% if ts -86400 < as_timestamp(now()) and light %}10
{% elif ts -86400 > as_timestamp(now()) and light %}50
{% else %}255
{% endif %}
rgb_color: >
{% set ts = as_timestamp(states.sun.sun.attributes.next_rising) %}
{% set light = is_state('light.lenta_gostinaia', 'off') %}
{% if ts -86400 < as_timestamp(now()) and light %}[255,132,2]
{% else %}[255,255,255]
{% endif %}
- service_template: light.toggle
entity_id: light.lenta_gostinaia
data_template:
brightness: >
{%- set ts = as_timestamp(states.sun.sun.attributes.next_rising) -%}
{%- set light = is_state('light.lenta_gostinaia', 'off') -%}
{% if ts -86400 < as_timestamp(now()) and light %}127
{% else %}10
{% endif %}
rgb_color: >
{%- set ts = as_timestamp(states.sun.sun.attributes.next_rising) -%}
{%- set light = is_state('light.lenta_gostinaia', 'off') -%}
{% if ts -86400 < as_timestamp(now()) and light %}[{{255|int}},{{255|int}},{{255|int}}]
{% else %}[{{255|int}},{{132|int}},{{2|int}}]
{% endif %}
I change script a little, in dev_template i see, what i need:
brightness: >10
rgb_color: >[255,132,2]
But when i try to fire an automation, i have an error: Error while executing automation automation.gostinaia_knopka_lenta. Invalid data for call_service at pos 1: None for dictionary value @ data[‘rgb_color’]
I don’t believe, i tested it. Yes, documentation says that it is possible, but when i fire light.toggle with color and brightness parameters, light switch’s on with previous state.
Does it work when you use this template? It doesn’t use light.toggle and selects either light_turn_on or light.turn_off depending on the state of light.lenta_gostinaia.
service_template: "{{ 'light.turn_on' if is_state('light.lenta_gostinaia', 'off') else 'light.turn_off' }}"