Denkovi Relay - command_state


I have a Denkovi WiFi relay board, with 16 relays.

The example configuration sets up each relay as a switch, and uses a python script to query the state. The python script connects to the WiFi board via TCP and gets a two byte response, with each bit equating to one of the 16 relays.

The problem I am having is that the command_state script is run 16 times in quick succession (once for each relay) no matter what the scan_interval is set to - this exceeds the maximum 5 TCP connections offered by the WiFi board. (from memory this happens in about 0.2s)

I could potentially cache the relay board response to a file, and then read status from the file, but is there a more elegant way within Home Assistant to either read the status once for all 16 relays, or at least rate limit the status requests?

Example below is for Relay_01. Note that the value template changes for each switch - the 128 below becomes 64 for Relay_02, 32 for Relay_03, etc.

command_state: python3 /config/WiFi_16_Relay.TCP/
value_template: "{{ value.split(' ')[0] | int | bitwise _and(128) > 0 }}"