Update sensor with automation

Hello. I’m sorry for the long post, but I think this may actually help others who are in my same situation:
I use Vivint for my home alarm. Unfortunately this alarm is no longer supported by HA as far as I know. However, it occurred to me that if I add a smart plug to vivint’s smart panel and set an automation through the Vivint app to turn on the plug when the alarm is armed and turn it off when the alarm is disarmed, I could power an ESP from said plug to send an mqtt message to HA to at least let me know the alarm is set or not. I have configured an ESP to just send an mqtt message to a specific topic every second.
How can I set an entity or a logical sensor to switch from ARMED (when the mqtt topic is receiving messages from trhe ESP because it is powered ON) to DISARMED when the mqtt messages stop because the ESP is off since the plug has been turned off by the vivint automation.
Thanks a lot!

Create an MQTT Binary Sensor and set its expire_after option to 15 seconds. Make your ESP publish a message every 5 seconds (every second is needlessly frequent).

1 Like

Or use the status sensor on ESPhome (with API or MQTT). It will only update on connect / disconnect.

The you just need a template binary sensor to convert this status sensor to an alarm sensor.

binary_sensor:
  - platform: template
    sensors:
      alarm_armed:
        friendly_name: "Alarm Armed"
        value_template: >-
          {{ is_state('binary_sensor.your_esp_status_sensor_here', 'on') }}
        icon_template: >
          {% if iis_state('binary_sensor.your_esp_status_sensor_here', 'on') %}
            mdi:shield-check
          {% else %}
            mdi:shield-off
          {% endif 5%}

Thank you! I will give that a try

FWIW, from the viewpoint of robustness and reliability, the described method of reporting an alarm relies on far too many vulnerable systems. An alarm panel can signal an alarm even when AC power is unavailable. The described signaling technique fails if AC is out, if the smart plug fails, or if WiFi is down.

1 Like

That is all true. But considering that there is no proper implementation of this alarm and i have not been able to scrape its status from the Vivint website, this is the next best thing. Furthermore, I won’t be using this status for anything critical (turn on some lights at night if armed, etc). But I do understand your concern.

1 Like

Does the alarm panel have a battery backed power supply you can use to power the ESP?

Does it have a voltage free contact for alarm state (most do)?

If the answer to both is ‘yes’ then you would be better off monitoring the alarm state directly with the esp.

You could even monitor if the alarm was tripped.

binary_sensor:
  - platform: mqtt
    state_topic: "vivintalarm/status"
    payload_not_available: "Disarmed"
    payload_available: "Armed"
    name: "esp32_vivint_alarm_monitor"
    expire_after: 15

I created the following sensor. however when I see its state it appears to be “off”. I am also seeing this on the logs:

No matching payload found for entity: esp32_vivint_alarm_monitor with state topic: vivintalarm/status. Payload: Armed, with value template None

Any ideas?

Yes, by default an MQTT Binary Sensor expects to receive, via state_topic, a payload of ON or OFF (see payload_on). Unless you supply it either of those two values, it will complain the payload doesn’t match the expected values. You have specified values for other options that affect other aspects of the binary sensor’s behavior.

1 Like