Automation for Indicator RGB

Hey,

why isn’t my automation working in this configuration? If I break this up into 4 or 5 individual automations, it works fine.

where is the mistake? Thanks a lot

alias: PV-Anlage
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.sma_power_template
    above: 1
    value_template: "500"
condition: []
action:
  - service: light.turn_on
    data:
      brightness_pct: 25
      color_name: lightyellow
    target:
      device_id:
        - ac3e0f512467c0f578c06e119dcbe08c
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.sma_power_template
        above: 501
        below: 2500
    continue_on_timeout: false
  - service: light.turn_on
    data:
      color_name: red
      brightness_pct: 100
    target:
      device_id: ac3e0f512467c0f578c06e119dcbe08c
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.sma_power_template
        above: 2501
        below: 3500
    continue_on_timeout: false
  - service: light.turn_on
    data:
      color_name: yellow
      brightness_pct: 100
    target:
      device_id: ac3e0f512467c0f578c06e119dcbe08c
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.sma_power_template
        below: 7500
        above: 3501
    continue_on_timeout: false
  - service: light.turn_on
    data:
      color_name: darkgreen
      brightness_pct: 100
    target:
      device_id: ac3e0f512467c0f578c06e119dcbe08c
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.sma_power_template
        above: 7501
    continue_on_timeout: false
  - service: light.turn_on
    data:
      color_name: blue
      brightness_pct: 100
    target:
      device_id: ac3e0f512467c0f578c06e119dcbe08c
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.sma_power_template
        below: 1
    continue_on_timeout: false
  - service: light.turn_off
    data: {}
    target:
      device_id: ac3e0f512467c0f578c06e119dcbe08c
mode: restart

What are you expecting this to trigger on?

You are missing all your device ids:

No the Device ID exist
I’ve updated the code above again

You still didn’t address Tom’s question about this trigger:

You’re hard coding 500 as the value. You should remove the value_template: line.

Sorry i slipped in the line. I created the automation using the editor. But it still doesn’t grow.

The sensor shows me how much power my system is currently producing and the led should display a different color depending on the value.

Sorry im new in HA

Hey, nobody has an idea?

It’s very difficult to help you because you keep posting code that you are not actually using.

A better way to do this would be:

alias: PV-Anlage
description: ""
trigger:
  - platform: state
    entity_id: sensor.sma_power_template
    to: # a null "to state" triggers on every state change, ignores attribute changes
action:
  - service: light.turn_on
    target:
      entity_id: light.your_light_here # entity_id NOT device_id
    data:
      color_name: >
        {% set power == states('sensor.sma_power_template')|float(10101010) %}
        {% if power == 10101010 %}
          fuchsia {# error colour #}
        {% elif power <= 500 %}
          lightyellow
        {% elif 500 < power <= 2500 %}
          red
        {% elif 2500 < power <= 3500 %}
          yellow
        {% elif 3500 < power <= 7500 %}
          darkgreen
        {% else %}
          blue
        {% endif %}

I have added a colour (fuchsia, a bright pink/purple) to indicate if there is a problem with the power sensor.

1 Like

Hi @tom_l thanks for your quick reply.

That is not quite true. I am using this code from topic one. The device id exists and in the Value line i am slipped. But i have change this. I created the automation using the editior.

Thanks a lot for this Code this helps me very well. I check this and give feedback.

Hello @tom_l I tested this code but it doesn’t work. The light does not turn on or change color.
Where is my mistake, can you help me? I can not find my mistake

- id: '9999999999'
  alias: PV-Anlage
  description: ""
  trigger:
  - platform: state
    entity_id: sensor.sma_power_template
    to: 
  action:
  - service: light.turn_on
    target:
      entity_id: light.schreibtischlampe
    data:
      color_name: >
        {% set power == states('sensor.sma_power_template')|float(10101010) %}
        {% if power == 10101010 %}
          fuchsia {# error colour #}
        {% elif power <= 500 %}
          lightyellow
        {% elif 500 < power <= 2500 %}
          red
        {% elif 2500 < power <= 3500 %}
          yellow
        {% elif 3500 < power <= 7500 %}
          darkgreen
        {% else %}
          blue
        {% endif %}

There is no need to tag me in every post you make I am following the topic.

What errors related to this automation do you get in your log?

I am sorry.

In the log is nothing. The PV entry are the single automation. The other one call PV-Anlage.

That’s the logbook. Not what I meant.

Go to Settings → Logs.

:see_no_evil:

The Logs are empty. After Restart the System i have this in the Logs:

Logger: homeassistant.components.automation
Source: components/automation/config.py:207 
Integration: Automatisierung (documentation, issues) 
First occurred: 12:30:45 (1 occurrences) 
Last logged: 12:30:45

Automation with alias 'PV-Anlage' could not be validated and has been disabled: template value should be a string for dictionary value @ data['action'][0]['data']. Got OrderedDict([('color_name', "{% set power == states('sensor.sma_power_template')|float(10101010) %} {% if power == 10101010 %}\n fuchsia {# error colour #}\n{% elif power <= 500 %}\n lightyellow\n{% elif 500 < power <= 2500 %}\n red\n{% elif 2500 < power <= 3500 %}\n yellow\n{% elif 3500 < power <= 7500 %}\n darkgreen\n{% else %}\n blue\n{% endif %}")]

**Second Entry**

Logger: homeassistant.helpers.event
Source: helpers/template.py:460 
First occurred: 12:31:12 (1 occurrences) 
Last logged: 12:31:12

Error while processing template: Template("{{ iif(states('sensor.sma_power_total'), (states('sensor.sma_power_total') | float/1000) | round(0)) }}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1771, in forgiving_float_filter
    return float(value)
ValueError: could not convert string to float: 'unavailable'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 458, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2007, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1774, in forgiving_float_filter
    raise_no_default("float", value)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1472, in raise_no_default
    raise ValueError(
ValueError: Template error: float got invalid input 'unavailable' when rendering template '{{ iif(states('sensor.sma_power_total'), (states('sensor.sma_power_total') | float/1000) | round(0)) }}' but no default was specified

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 576, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 460, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: float got invalid input 'unavailable' when rendering template '{{ iif(states('sensor.sma_power_total'), (states('sensor.sma_power_total') | float/1000) | round(0)) }}' but no default was specified

**Third Entry**

Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:364 
First occurred: 12:31:12 (1 occurrences) 
Last logged: 12:31:12

TemplateError('ValueError: Template error: float got invalid input 'unavailable' when rendering template '{{ iif(states('sensor.sma_power_total'), (states('sensor.sma_power_total') | float/1000) | round(0)) }}' but no default was specified') while processing template 'Template("{{ iif(states('sensor.sma_power_total'), (states('sensor.sma_power_total') | float/1000) | round(0)) }}")' for attribute '_attr_native_value' in entity 'sensor.sma_power_total_template'

Thank you very much for your patience. I don’t get it right yet.

Any Ideas?