Deactivate / Activate an entity with automation

We control our 7 projectors in theatre with command_line in HA.
Command_line tryes to get a requst answer every 30 seconds:
If some of the projectors ar offline, commend_line is waiting for an answer (wich is of course not coming).
Since we have many requests the entire HA system is slowed down.
It would be nice if i could deactivate all command_line state request if
i can not ping the projectors for example.

- platform: command_line
  scan_interval: 30
  switches:
    projector_on_off:
      command_on: echo -e "\x30\x30\x50\x4f\x4e\x0d" | nc 192.169.4.10 1024
      command_off: echo -e "\x30\x30\x50\x4f\x46\x0d" | nc 192.169.4.10 1024
      command_state: echo -e -n "\x30\x30\x51\x50\x57\x0d" | nc 192.169.4.10 1024
      command_timeout: 1
      value_template: >-
        {% if '00001' in value %}
          True
        {% else %}
          false
        {% endif %}
      friendly_name: "Projector ON / OFF"
      icon_template: "{{'mdi:projector' if '001' in value else 'mdi:projector-off'}}"

There’s a way to achieve that now.

Instead of using scan_interval to control the polling frequency, use an automation with homeassistant.update_entity.

  • Set the value of scan_interval to a very large number so that it rarely ever updates automatically.
  • Create an automation that triggers at the desired frequency and calls homeassistant.update_entity to update switch.projector_on_off.
  • Add a condition to the automation that determines when it should or should not execute the service call. You will have to decide what’s the best way of determining that (perhaps with a Ping sensor).
1 Like

Thats great! Thank’s a lot!

1 Like