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 
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 ....
