Hello, I have a question, maybe someone can help me. I have a Sonoff NS Panel Pro, and I want to keep the space on my dashboard as minimalist as possible.
I would like to display all active lights in a rolling manner as text.
I imagine it like this:
Basement (1sec break) Hallway (1sec break) Living room (1sec break) and again from the beginning: Basement…hallway…living room until the light is turned off.
I’ve already tried a few things with Chat GPT but can’t find a solution. Can template sensors even work with time loops?
i’m not sure how detailed you need… and i see you’ve been here for a couple years, so will start high level and holler where you need more specifics… i don’t know of something that does it all automagically for you, so i’d use a card showing an input_text and rotating it periodically.
i’d use a text card showing a text entity, maybe like this:
type: custom:mushroom-title-card
title: '{{ states(''input_text.test_text'') }} !'
alignment: center
then set automation to cycle through the lights. in order to do that, i’d prob create an input_number to track which light i’m showing and then increment that through all.
i don’t think template sensors update frequently enough for you to do this.
1 Like
I’ve already tried around with input_text and set value. But I don’t know what to do with automation. Could you please show me your automation?
i dont get it, chat-gpt also suffer:
alias: Rollende Lichtanzeige
trigger:
- platform: time_pattern
seconds: /1
- platform: state
entity_id: input_number.licht_index
action:
- service: input_text.set_value
target:
entity_id: input_text.licht_status
data_template:
value: >
{% set light_entities = ['input_boolean.test1', 'input_boolean.test2', 'input_boolean.test3'] %}
{% set active_lights = states | selectattr('entity_id', 'in', light_entities) | selectattr('state', 'eq', 'on') | map(attribute='name') | list %}
{% if active_lights %}
{% set index = states('input_number.licht_index')|int %}
{{ active_lights[index % active_lights | length] }}
{% else %}
No light is on
{% endif %}
- condition: template
value_template: "{{ states | selectattr('entity_id', 'in', ['input_boolean.test1', 'input_boolean.test2', 'input_boolean.test3']) | selectattr('state', 'eq', 'on') | list | count > 0 }}"
- service: input_number.increment
target:
entity_id: input_number.licht_index
- condition: template
value_template: "{{ states | selectattr('entity_id', 'in', ['input_boolean.test1', 'input_boolean.test2', 'input_boolean.test3']) | selectattr('state', 'eq', 'on') | list | count == 0 }}"
- service: input_number.set_value
target:
entity_id: input_number.licht_index
data_template:
value: 0
give this a try…
definitely can tighted up the code. its late and i got lazy about resetting the counter. ideally you do it to the max of lights on, but it will also work if you set the counter limit to an arbitrarily large number greater than the total max possible lights.
from looking at what you have, it looks like you’re jinja capable, so i’m guessing you can take it from here?
note, i ended using a counter helper because it has a max and easy increment rather than an input_number.
alias: test cycle lights label
trigger:
- platform: time_pattern
seconds: /1
condition: []
action:
- service: input_text.set_value
target:
entity_id: input_text.test_text
data:
value: >
{% set all_lights_on = states.light | selectattr('state', 'eq', 'on') | list %}
{% set lights_on_count = all_lights_on | count %}
{% set light_index = states('counter.test_light_on_index') | int % lights_on_count %}
{{ all_lights_on[light_index].attributes['friendly_name'] }}
- service: counter.increment
target:
entity_id: counter.test_light_on_index
- if:
- condition: template
value_template: >-
{{ states('counter.test_light_on_index') | int == state_attr('counter.test_light_on_index', 'maximum') }}
then:
- service: counter.reset
target:
entity_id: counter.test_light_on_index
2 Likes
Oh man, you just saved my weekend. Works like a charm
I revised it a bit (I have different entities with different domains)
alias: Rollierender Lichtstatus
description: ""
trigger:
- platform: time_pattern
seconds: /1
action:
- service: input_text.set_value
target:
entity_id: input_text.licht_status
data_template:
value: |
{% set entities_to_check = [
'switch.00161a499cb9a2_2',
'switch.00161a499cb9a2_18',
'light.00169be9a0f15a_10',
'switch.00161a499cb98e_26',
'light.led_wohnzimmer',
'switch.00161a499cb98e_6',
'light.ambilight',
'switch.00161a499cb98e_2',
'light.00169be992f89f_10',
'switch.00161a499cb9a2_10',
'switch.00161a499cb98e_10',
'light.ambilight_arbeitszimmer',
'input_boolean.helfer_spiegelschrank',
'light.led_badezimmer_oben',
'light.led_badezimmer_unten',
'switch.00161a499cb9a2_30',
'light.led_schlafzimmer',
'light.deckenventilator',
'light.00169be992f89f_2',
'light.00169be992f89f_6',
'light.00169be9a0f15a_6',
'light.00169be9a0f15a_2',
'switch.00161a499cb9a2_14'
] %}
{% set entities_on = states
| selectattr('entity_id', 'in', entities_to_check)
| selectattr('state', 'eq', 'on')
| list %}
{% if entities_on %}
{% set lights_on_count = entities_on | count %}
{% set light_index = states('counter.licht_on_index') | int % lights_on_count %}
{{ entities_on[light_index].attributes['friendly_name'] }}
{% else %}
{% endif %}
- service: counter.increment
target:
entity_id: counter.licht_on_index
data: {}
- if:
- condition: template
value_template: >-
{{ states('counter.licht_on_index') | int ==
state_attr('counter.licht_on_index', 'maximum') }}
then:
- service: counter.reset
target:
entity_id: counter.licht_on_index
data: {}
awesome!
a suggestion for you to make future maintenance easier… looks like you have switches that are actually controlling lights… You can go to the entity and set them as lights and ha will create a light entity to mirror the switch (so nothing breaks)…
but that then let’s you create a single light group for all of this. Then this automation can point to the light group instead of hard coding the list. And you can manage the list via the group UI…
Still works the same but you earn code beauty points
I am a technician and like to stick to the principle: “Never touch a running system”, but I am also a perfectionist . I’ll try it But I assume that all hard coded yaml sensors/entries need to be adjusted?
No… home assistant will hide the switch but it’s still there . So things will continue to work. Can migrate at your leisure