Expert advice needed to improve my automations

Hi, need some expert advice
i have at home an IP controller where i can send and retrieve HEX values to turn on my lighs
so i created switches to turn on / off my lights, thats working verry good with shell commands
now i have improved my app, to also change the state of my light to ON and OFF, if i turn on/off my light from outside HA …
so i have setup a sensor , that sensors contains a lot of bits, every pair of 2 bits , tells me if a light is on or off
for example … in reality this is a long string, depending of my lights, about 30 of them, so a 60 bit string
00000000… => 4 lights OFF
01010000… => first 2 lights on, next 2 lights off
quite easy to program … BUT
see below my code
so for every substring i have an automation , like 30 of them, if the value changes, i just change the state of my light, since its already on/ff from outside HA…
but the problem is, that if 1 light changes to 00 or 01 , the sensor is actually refreshed, and ALL my automations run, just changing the state, while its not needed, only 1 automation should run offcourse :slight_smile:
so in reality , if i change 1 light, HA is sending 30 shell commands every time, and since i have implemented this, i see sometines in the log, that a curl command was excited, or even sometimes HA crashes and restarts…

how can i improve this? can i run an specific automation IF ONLY a part of a sensor changes?
i was also thinking about making 30 substring sensors, based on the main value, but i think the end result will be the same, becausse if my main sensor changes, all sub sensors will also change

thnx in advance , i hope my explemantion is clear…

value sensor example : 000001000000000000… => this turns on “Light Bureau aan”

#AUTOMATION (example 1 light ON)  ... that [4:6] , is actually my thrid light, so everty automation is the same , only this changes [8:10] .. [10:12] .....

- alias: Light Bureau aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[4:6] == '01' }}"
  action:
  - service: shell_command.state_bureau_on

#AUTOMATION (example 1 light OFF)

  - alias: Light Bureau uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[4:6] == '00' }}"
  action:
  - service: shell_command.state_bureau_off
  
# SHELL COMMANDS :

state_bureau_on: "curl  -k POST -d '{\"state\": \"on\",\"attributes\": {\"assumed_state\": true,\"friendly_name\": \"Bureau\",\"icon\": \"mdi:lightbulb-on\"}}' https://127.0.0.1:8123/api/states/light.bureau?api_password=blabla"
state_bureau_off: "curl  -k POST -d '{\"state\": \"off\",\"attributes\": {\"assumed_state\": true,\"friendly_name\": \"Bureau\",\"icon\": \"mdi:lightbulb-on\"}}' https://127.0.0.1:8123/api/states/light.bureau?api_password=blabla"
# .... and a lot more of these ....

This should just be one automation, no condition and a service template to decide which script to run…

can you guide me? make me a small example?

you could try something like this:

  action:
    service_template: >
      shell_command.state_bureau_{{ 'off' if states.sensor.Prog.state[4:6] == '00' else 'on'}} 

though Id add a condition to be sure the state is either ‘on’ or ‘off’:

condition:
  condition: template
  value_template: >
    {{ states.sensor.Prog.state[4:6] in ['on','off'] }}

normally I write these if states templates in the form of {{ 'off' if is_state('sensor.Prog','on') else 'on'}}, but in this case the extra [4:6] makes me uncertain doing so is possible.

in your case, i still have the 30 x automations? am i right?
while in the other person reply above, he said that it can be done in 1 x automation ?
not a big deal though if i have 30 of them, if it works, its good enough for me

edit

i mean instead of 60 x automations for on and off, i can reduce it to 30 x ? just 1 automation per light for on / off ?

not sure of the rest of your wishes, but I shrank your 2 automations into 1 :wink:
maybe they can all fit into this 1 by expanding further into a map or so, but we’d need to have some more info I guess.
But let @anon43302295 give you his ideas, he’s the templating man to go to for sure. Id be very interested too

ok, so i can shrink it in to 30 x automations , but still, will this help my issue?
so if 1 light , changes, the other 29x automations will not run/change ?

yes, I think that should be possible using a map. I’ll give you an example, you’d need to change with your own details of course:

    entity_picture_template: >
      {% set mapper = 
        { 'Breezy': 'cloudy',
          'Clear Night': 'night',
          'Clear': 'day',
          'Mostly Clear': 'day',
          'Clear Day': 'day', 
          'Cloudy': 'cloudy',
          'Fog': 'cloudy',
          'Hail': 'rainy-7',
          'Lightning': 'thunder',
          'Mostly Cloudy': 'cloudy',
          'Partly Cloudy': 'cloudy-day-3',
          'Rain': 'rainy-4',
          'Scattered Showers': 'rainy-3',
          'Showers': 'rainy-6',
          'Snow': 'snowy-6',
          'Mostly Sunny': 'day',
          'Sunny': 'day',
          'Windy': 'cloudy'} %}
      {% set state = states('sensor.yweather_current') %}
      {% set weather = mapper[state] if state in mapper else 'weather' %}
      {% set path = '/local/weather/animated/' %}
      {% set ext = '.svg'%}
        {{[path,weather,ext]|join('')|lower}}

If you could fit your 30 switches into a map like this, you could then use this map to select the right switch in the template, and use the service_template…
But, a big but, I say this purely based on the experience I have with rather easily mappable entities. Not sure if what you need fits… You might ask @petro for help on the map(per).

that map is indeed interesting , and complicated

but your first suggestion about reducing, gonna try that also , dont mind to have 30 x automations, as long as it works :slight_smile:

but will it fix my issue?

Can you paste all 60 automations (either here or on a pastebin somewhere) please and I’ll take a look :slight_smile:

offcourse, its less then 60 , it was just an example offcourse… but i am intending to make more :slight_smile:
you will also see 1 exception , thats a dimmer light, gonna make some more of those, there the hex value is 00 for Off, and 01-99 is represensting an brightess value , but the curl/action behind it, is the same
its the automation with : states.sensor.Prog.state[36:38] != ‘00’

- alias: SC Living aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[30:32] == '01' }}"
  action:
  - service: shell_command.sc_living_on
- alias: SC Living uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[30:32] == '00' }}"
  action:
  - service: shell_command.sc_living_off

- alias: SC Eetkamer aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[32:34] == '01' }}"
  action:
  - service: shell_command.sc_eetkamer_on
- alias: SC Eetkamer uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[32:34] == '00' }}"
  action:
  - service: shell_command.sc_eetkamer_off  
  
- alias: SC Bureau aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[34:36] == '01' }}"
  action:
  - service: shell_command.sc_bureau_on
- alias: SC Bureau uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[34:36] == '00' }}"
  action:
  - service: shell_command.sc_bureau_off  
  
- alias: Dimmer 1 aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[36:38] != '00' }}"
  action:
  - service: shell_command.state_dimmer1_on
- alias: Dimmer 1 uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[36:38] == '00' }}"
  action:
  - service: shell_command.state_dimmer1_off  
  
- alias: Light Bureau aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[4:6] == '01' }}"
  action:
  - service: shell_command.state_bureau_on
- alias: Light Bureau uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[4:6] == '00' }}"
  action:
  - service: shell_command.state_bureau_off

- alias: Light Eetkamer aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[6:8] == '01' }}"
  action:
  - service: shell_command.state_eetkamer_on
- alias: Light Eetkamer uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[6:8] == '00' }}"
  action:
  - service: shell_command.state_eetkamer_off

- alias: Light Living aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[8:10] == '01' }}"
  action:
  - service: shell_command.state_living_on
- alias: Light Living uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[8:10] == '00' }}"
  action:
  - service: shell_command.state_living_off

- alias: Light Keukenraam aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[10:12] == '01' }}"
  action:
  - service: shell_command.state_keukenraam_on
- alias: Light Keukenraam uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[10:12] == '00' }}"
  action:
  - service: shell_command.state_keukenraam_off  
  
- alias: Light Keukeneiland aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[12:14] == '01' }}"
  action:
  - service: shell_command.state_keukeneiland_on
- alias: Light Keukeneiland uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[12:14] == '00' }}"
  action:
  - service: shell_command.state_keukeneiland_off  
  
- alias: Light Keukendoorgang aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[14:16] == '01' }}"
  action:
  - service: shell_command.state_keukendoorgang_on
- alias: Light Keukendoorgang uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[14:16] == '00' }}"
  action:
  - service: shell_command.state_keukendoorgang_off  
  
- alias: Light Keuken aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[12:16] == '0101' }}"
  action:
  - service: shell_command.state_keuken_on
- alias: Light Keuken uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[12:16] == '0000' }}"
  action:
  - service: shell_command.state_keuken_off   
  
- alias: Light Inkomhal aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[16:18] == '01' }}"
  action:
  - service: shell_command.state_inkomhal_on
- alias: Light Inkomhal uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[16:18] == '00' }}"
  action:
  - service: shell_command.state_inkomhal_off 

- alias: Light Led Keuken aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[18:20] == '01' }}"
  action:
  - service: shell_command.state_led_keuken_on
- alias: Light Led Keuken uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[18:20] == '00' }}"
  action:
  - service: shell_command.state_led_keuken_off   
  
- alias: Light Led Bureau aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[20:22] == '01' }}"
  action:
  - service: shell_command.state_led_bureau_on
- alias: Light Led Bureau uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[20:22] == '00' }}"
  action:
  - service: shell_command.state_led_bureau_off    

- alias: Light Spots Tuinhuis aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[22:24] == '01' }}"
  action:
  - service: shell_command.state_spotstuinhuis_on
- alias: Light Spots Tuinhuis uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[22:24] == '00' }}"
  action:
  - service: shell_command.state_spotstuinhuis_off 

- alias: Light Spots Terras aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[24:26] == '01' }}"
  action:
  - service: shell_command.state_spotsterras_on
- alias: Light Spots Terras uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[24:26] == '00' }}"
  action:
  - service: shell_command.state_spotsterras_off  
  
- alias: Light Terras aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[26:28] == '01' }}"
  action:
  - service: shell_command.state_terras_on
- alias: Light Terras uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[26:28] == '00' }}"
  action:
  - service: shell_command.state_terras_off

- alias: Light Avond Terras aan
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[28:30] == '01' }}"
  action:
  - service: shell_command.state_avondterras_on
- alias: Light Avond Terras uit
  initial_state: 'on'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[28:30] == '00' }}"
  action:
  - service: shell_command.state_avondterras_off

i also have 4 special automations, based on the same logic, but the action is not a shell command, but turning on my media player, this based on that same HEX string, together with the lighs, these offcourse also run, but without an impact though… but also nice if its in the same mapping…

- alias: Badkamer Radio aan
  initial_state: 'on'
  id: '1513037592907'
  trigger:
  - entity_id: sensor.Prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[0:2] == '01' }}"
  action:
  - service: media_player.turn_on
    entity_id: media_player.zone2

#radio uit badkamer
- alias: Badkamer Radio uit
  initial_state: 'on'
  id: '1513037592908'
  trigger:
  - entity_id: sensor.Prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[0:2] == '00' }}"
  action:
  - service: media_player.turn_off
    entity_id: media_player.zone2  
#radio aan nachthal
- alias: Nachthal Radio aan
  initial_state: 'on'
  id: '1513037592909'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[2:4] == '01' }}"
  action:
  - service: media_player.turn_on
    entity_id: media_player.zone3
  - service: switch.turn_on
    entity_id: switch.sc_living
  
#radio uit nachthal
- alias: Nachthal Radio uit
  initial_state: 'on'
  id: '1513037592910'
  trigger:
  - entity_id: sensor.prog
    platform: state
  condition:
  - condition: template
    value_template: "{{ states.sensor.Prog.state[2:4] == '00' }}"
  action:
  - service: media_player.turn_off
    entity_id: media_player.zone3

From a million automations over 377 lines, to one automation of 43 lines…

- alias: the mf_social amazing consolidation automation
  initial_state: 'on'
  trigger:
    entity_id: sensor.prog
    platform: state
  action:
    service_template: >
      {% if states.sensor.Prog.state[30:32] == '01' %} shell_command.sc_living_on
      {% elif states.sensor.Prog.state[30:32] == '00' %} shell_command.sc_living_off
      {% elif states.sensor.Prog.state[32:34] == '01' %} shell_command.sc_eetkamer_on
      {% elif states.sensor.Prog.state[32:34] == '00' %} shell_command.sc_eetkamer_off
      {% elif states.sensor.Prog.state[34:36] == '01' %} shell_command.sc_bureau_on
      {% elif states.sensor.Prog.state[34:36] == '00' %} shell_command.sc_bureau_off
      {% elif states.sensor.Prog.state[36:38] != '00' %} shell_command.state_dimmer1_on
      {% elif states.sensor.Prog.state[36:38] == '00' %} shell_command.state_dimmer1_off
      {% elif states.sensor.Prog.state[4:6] == '01' %} shell_command.state_bureau_on
      {% elif states.sensor.Prog.state[4:6] == '00' %} shell_command.state_bureau_off
      {% elif states.sensor.Prog.state[6:8] == '01' %} shell_command.state_eetkamer_on
      {% elif states.sensor.Prog.state[6:8] == '00' %} shell_command.state_eetkamer_off
      {% elif states.sensor.Prog.state[8:10] == '01' %} shell_command.state_living_on
      {% elif states.sensor.Prog.state[8:10] == '00' %} shell_command.state_living_off
      {% elif states.sensor.Prog.state[10:12] == '01' %} shell_command.state_keukenraam_on
      {% elif states.sensor.Prog.state[10:12] == '00' %} shell_command.state_keukenraam_off
      {% elif states.sensor.Prog.state[12:14] == '01' %} shell_command.state_keukeneiland_on
      {% elif states.sensor.Prog.state[12:14] == '00' %} shell_command.state_keukeneiland_off
      {% elif states.sensor.Prog.state[14:16] == '01' %} shell_command.state_keukendoorgang_on
      {% elif states.sensor.Prog.state[14:16] == '00' %} shell_command.state_keukendoorgang_off
      {% elif states.sensor.Prog.state[12:16] == '0101' %} shell_command.state_keuken_on
      {% elif states.sensor.Prog.state[12:16] == '0000' %} shell_command.state_keuken_off
      {% elif states.sensor.Prog.state[16:18] == '01' %} shell_command.state_inkomhal_on
      {% elif states.sensor.Prog.state[16:18] == '00' %} shell_command.state_inkomhal_off
      {% elif states.sensor.Prog.state[18:20] == '01' %} shell_command.state_led_keuken_on
      {% elif states.sensor.Prog.state[18:20] == '00' %} shell_command.state_led_keuken_off
      {% elif states.sensor.Prog.state[20:22] == '01' %} shell_command.state_led_bureau_on
      {% elif states.sensor.Prog.state[20:22] == '00' %} shell_command.state_led_bureau_off
      {% elif states.sensor.Prog.state[22:24] == '01' %} shell_command.state_spotstuinhuis_on
      {% elif states.sensor.Prog.state[22:24] == '00' %} shell_command.state_spotstuinhuis_off
      {% elif states.sensor.Prog.state[24:26] == '01' %} shell_command.state_spotsterras_on
      {% elif states.sensor.Prog.state[24:26] == '00' %} shell_command.state_spotsterras_off
      {% elif states.sensor.Prog.state[26:28] == '01' %} shell_command.state_terras_on
      {% elif states.sensor.Prog.state[26:28] == '00' %} shell_command.state_terras_off
      {% elif states.sensor.Prog.state[28:30] == '01' %} shell_command.state_avondterras_on
      {% else % } shell_command.state_avondterras_off {% endif %}

Including those other 4 takes it up to 51 lines…

- alias: the mf_social amazing consolidation automation
  initial_state: 'on'
  trigger:
    entity_id: sensor.prog
    platform: state
  action:
    service_template: >
     {% if not (states.sensor.Prog.state[2:4] == '00') or not (states.sensor.Prog.state[0:2] == '00') %} homeassistant.turn_on
     {% else % } homeassistant.turn_off {% endif %}
    data_template:
      entity_id: >
        {% if states.sensor.Prog.state[0:2] == '01' %} media_player.zone2
        {% elif states.sensor.Prog.state[2:4] == '01' %} media_player.zone3, switch.sc_living
        {% elif states.sensor.Prog.state[0:2] == '00' %} media_player.zone2
        {% elif states.sensor.Prog.state[2:4] == '00' %} media_player.zone3
        {% elif states.sensor.Prog.state[30:32] == '01' %} shell_command.sc_living_on
        {% elif states.sensor.Prog.state[30:32] == '00' %} shell_command.sc_living_off
        {% elif states.sensor.Prog.state[32:34] == '01' %} shell_command.sc_eetkamer_on
        {% elif states.sensor.Prog.state[32:34] == '00' %} shell_command.sc_eetkamer_off
        {% elif states.sensor.Prog.state[34:36] == '01' %} shell_command.sc_bureau_on
        {% elif states.sensor.Prog.state[34:36] == '00' %} shell_command.sc_bureau_off
        {% elif states.sensor.Prog.state[36:38] != '00' %} shell_command.state_dimmer1_on
        {% elif states.sensor.Prog.state[36:38] == '00' %} shell_command.state_dimmer1_off
        {% elif states.sensor.Prog.state[4:6] == '01' %} shell_command.state_bureau_on
        {% elif states.sensor.Prog.state[4:6] == '00' %} shell_command.state_bureau_off
        {% elif states.sensor.Prog.state[6:8] == '01' %} shell_command.state_eetkamer_on
        {% elif states.sensor.Prog.state[6:8] == '00' %} shell_command.state_eetkamer_off
        {% elif states.sensor.Prog.state[8:10] == '01' %} shell_command.state_living_on
        {% elif states.sensor.Prog.state[8:10] == '00' %} shell_command.state_living_off
        {% elif states.sensor.Prog.state[10:12] == '01' %} shell_command.state_keukenraam_on
        {% elif states.sensor.Prog.state[10:12] == '00' %} shell_command.state_keukenraam_off
        {% elif states.sensor.Prog.state[12:14] == '01' %} shell_command.state_keukeneiland_on
        {% elif states.sensor.Prog.state[12:14] == '00' %} shell_command.state_keukeneiland_off
        {% elif states.sensor.Prog.state[14:16] == '01' %} shell_command.state_keukendoorgang_on
        {% elif states.sensor.Prog.state[14:16] == '00' %} shell_command.state_keukendoorgang_off
        {% elif states.sensor.Prog.state[12:16] == '0101' %} shell_command.state_keuken_on
        {% elif states.sensor.Prog.state[12:16] == '0000' %} shell_command.state_keuken_off
        {% elif states.sensor.Prog.state[16:18] == '01' %} shell_command.state_inkomhal_on
        {% elif states.sensor.Prog.state[16:18] == '00' %} shell_command.state_inkomhal_off
        {% elif states.sensor.Prog.state[18:20] == '01' %} shell_command.state_led_keuken_on
        {% elif states.sensor.Prog.state[18:20] == '00' %} shell_command.state_led_keuken_off
        {% elif states.sensor.Prog.state[20:22] == '01' %} shell_command.state_led_bureau_on
        {% elif states.sensor.Prog.state[20:22] == '00' %} shell_command.state_led_bureau_off
        {% elif states.sensor.Prog.state[22:24] == '01' %} shell_command.state_spotstuinhuis_on
        {% elif states.sensor.Prog.state[22:24] == '00' %} shell_command.state_spotstuinhuis_off
        {% elif states.sensor.Prog.state[24:26] == '01' %} shell_command.state_spotsterras_on
        {% elif states.sensor.Prog.state[24:26] == '00' %} shell_command.state_spotsterras_off
        {% elif states.sensor.Prog.state[26:28] == '01' %} shell_command.state_terras_on
        {% elif states.sensor.Prog.state[26:28] == '00' %} shell_command.state_terras_off
        {% elif states.sensor.Prog.state[28:30] == '01' %} shell_command.state_avondterras_on
        {% else % } shell_command.state_avondterras_off {% endif %}

ok, looks indeed simple, but there is only x shell command, for only the hex that are changed
so if 2 lights are changing, only 2 shell commands are fired?

have you also had a look at those other 4 automations i posted later

anyway; can i do donations for your work and time?

Yeah, so if you need it to combine it so that all the bits are examined you’ll need something a bit more complicated to generate a comma separated string of the entity_id’s that need to be affected, but it’s doable.

That said, I don’t really still get quite how your system does what it does, I just looked at the code and shrank it, so there’s potential that with each change to the sensor.prog it will fire quickly enough that you don’t need to worry about iterating over it.

See the info badges of my Readme on Github to buy me a beer if you so desire…

link removed

…but it’s not necessary :slight_smile:

I would change that sensor.prog and avoid all those automations and the curl posts. If I get it right you have some light control system that can be changed outside HA, so you need to sync HA with the light states as well control the lights form HA (the last part I’m not sure). Are you using the template light component?

Another take on the problem should be posting the states/commands to a MQTT.

correct, i have some kind of IP controller, thats is connected to my dumb wall switches
but i was able to retrieve the API from manufacter
and the only way to turn on/off a light , turn up/down screens and othre things is to send some kind of HEX code, to turn on a specific entity, that was not difficult, i used indeed a template light, where i also fire a shell command … that fires a .py script with echo “blabla” | nc 192.168.0.1 … quite easy

but to also change the state , indeed if i turn ON/off light from outside, i started now to retrieve the HEX value and accomplished this with automations / states …

gonna test it out , fingers crossed :slight_smile:

hmm, gives me an configuration error:

Configuration invalidCHECK CONFIG

Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token ‘end of statement block’, got ‘%’) for dictionary value @ data[‘action’][0][‘service_template’].