A device's state stuck. how often should i restart HA?

when back door is open, it sends an alert via PushBullet to my phone.
today i did not receive any notification even though i opened by door. looking at History, i see the door state “open” since 7pm yesterday. even though it was closed at 8pm.
restart HA fixed the state. so now, how often should i restart HA?
should i set up a cron job to restart every day at 2am?
sudo systemctl restart [email protected]

Ideally, never.

looking at History, i see the door state “open” since 7pm yesterday. even though it was closed at 8pm.

What are you using to report the door’s state to Home Assistant?

restart HA fixed the state.

Only because restarting forced a complete refresh of everything. This should never be considered to be a requirement to ensure the system maintains its integrity. It simply means something else is unreliable and should be corrected.

Please share the details of your configuration and we may be able to help you identify the source of the problem.

1 Like

@tung256,
I continue to have a similar problem. My system uses a Vera controller as the z-wave interface and I routinely ‘see’ the door open event on the binary switch BUT almost never ‘see’ the closure (or return to the OFF state) of the same binary sensor. I have used some creative automations to help reset these hung sensors, but even that is somewhat unreliable. Included below is both the automation and script. Maybe it will help. I’m also open to any suggestions or better ideas.

#################################################################
##  The Front Door Sensor is ON -> Force Reset
#################################################################
- id: front_door_sensor_on
  alias: Front Door Sensor On
  initial_state: 'on'
  trigger:
  - platform: template
    value_template: '{% if (as_timestamp(now())-as_timestamp(states.binary_sensor.front_door_31.last_changed)) > 60 %}true{% endif %}'
  - platform: template
    value_template: '{% if (as_timestamp(now())-as_timestamp(states.binary_sensor.front_door_31.last_changed)) > 120 %}true{% endif %}'
  - platform: template
    value_template: '{% if (as_timestamp(now())-as_timestamp(states.binary_sensor.front_door_31.last_changed)) > 300 %}true{% endif %}'
  - platform: template
    value_template: '{% if (as_timestamp(now())-as_timestamp(states.binary_sensor.front_door_31.last_changed)) > 600 %}true{% endif %}'
  - platform: template
    value_template: '{% if (as_timestamp(now())-as_timestamp(states.binary_sensor.front_door_31.last_changed)) > 1800 %}true{% endif %}'
#   [60=1 min, 120=2 min, 300=5 min, 600=10 min, 1800=30 min]
  - platform: time_pattern
    hours: 1
    minutes: 0
    seconds: 0
  condition:
  - condition: state
    entity_id: alarm_control_panel.ha_alarm
    state: 'disarmed'
  - condition: state
    entity_id: switch.front_door_31
    state: 'on'
  - condition: state
    entity_id: binary_sensor.front_door_31
    state: 'on'
  action:
  - service: script.turn_on
    entity_id: script.reset_front_door_sensor
#

#
#################################################################
# Reset Front Door Sensor
# Called from [PreSet Alarm to Armed Away]
# In file: [automations/alarm_panel.yaml]
# Called from [Sensor Automations] (Tripped, 1 min Timer)
# In file: [automations/sensor.yaml]
## Called from [update_front_door_sensor_on_lock]
## In file: [automations/door_locks.yaml]
#################################################################
reset_front_door_sensor:
  alias: Reset Front Door Sensor
  sequence:
  - service: script.write_to_log
    data:
      entity_id: switch.front_door_31
      message: 'Reset Front Door Sensor'
  - service: switch.turn_off
    data:
      entity_id: switch.front_door_31
  - delay: '00:00:05'
  - service: switch.turn_on
    data:
      entity_id: switch.front_door_31
  - service: homeassistant.update_entity
    data:
      entity_id: binary_sensor.front_door_31
  - wait_template: "{{ is_state('binary_sensor.front_door_31', 'off') }}"
    timeout: '00:00:10'
    continue_on_timeout: 'true'
  - condition: state
    entity_id: input_boolean.enable_sensor_notifications
    state: 'on'
  - service: persistent_notification.create
    data:
      message: "At {{now().strftime('%m/%d/%Y %H:%M:%S')}} the FRONT DOOR sensor was reset (Zone-Toggled)."
      title: "Door Sensor Alert"
#

What is the configuration for binary_sensor.front_door_31?

you want to see the configuration.yaml and automation.yaml right?

Feel free to share as much as you want but all I want to see is the configuration for binary_sensor.front_door_31.

@123: I’m not sure what you are looking for, as far as the configuration of the binary sensor. It is a component imported into H/A via the Vera hub. Maybe this bit of text from the Vera Hub page will crear things up for you:

SENSOR

The vera platform allows you to get data from your Vera sensors from within Home Assistant.

Please note that some vera sensors (such as motion and flood sensors) are armable which means that vera will send alerts (email messages to txts) when they are armed and change state.

Home Assistant will display the state of these sensors regardless of the armed state.

To allow you to change the armed state - Home Assistant will create a switch as well as a sensor for each Armable sensor. You can hide these switches using customization if you wish.

Therefore I do not have any specific lines in any yaml file that define the specific properties of the binary sensor. H/A does it automatically via the hub component. https://www.home-assistant.io/components/vera/

Entity:
[binary_sensor.front_door_31]
State:
Off
Attributes:
battery_level: 100
device_armed: True
last_tripped_time: 2019-05-29T13:40:55+00:00
device_tripped: False
Vera Device Id: 31
friendly_name: Front Door
device_class: door

and

Entity:
[switch.front_door_31]
State:
On
Attributes:
battery_level: 100
device_armed: True
last_tripped_time: 2019-05-29T13:40:55+00:00
device_tripped: False
Vera Device Id: 31
friendly_name: Front Door

That’s what I needed to know.

So the possibility of misconfiguration is next to zero because it all hinges on the vera component which simply requires an IP address to establish a connection and perform automatic discovery.

Is it always the same binary_sensor or are there others with the same issue? Or is this the sole binary_sensor so you can’t compare its performance to others?

If all binary_sensors have the same issue then it suggests a potential glitch in the vera component.

@123: There are a total of 7 of these binary_sensors, all the same brand and all 100% accurate in the Vera UI. All react about the same in H/A - generally seeing the open event (albeit sometimes quite slow), but very rarely seeing the close event. Doors that were physically closed but still reported as open were reeking havoc on the alarm being set, so I was forced to cycle through any sensor that was hung open, toggle the switch which resets the binary sensor, then set the alarm.
There are also two Garage Door Tilt Sensors that get imported in the same fashion (switch and binary sensor) that are from another mfg. These do seem to work better than the door/window sensors. Both the door/window and garage door tilt sensors are battery operated in case you are wondering. No issues reading battery levels in H/A, just seeing the closed event.

It seems to suggest some kind of deficiency in the vera component … or in the Vera device’s ability to report closed states for binary_sensors. However, the deficiency seem highly device-specific and one-sided (closed states only). Almost makes you wonder about the brand/model of the zwave sensor … but then you confirmed it works flawlessly in Vera’s UI. Sure is a head-scratcher.

Whereas an MQTT Binary sensor offers an optional band-aid in the form of an off_delay, I see the vera component’s documentation offers no comparable remedy.

I was hoping to offer you some other way to resolve this but it would appear the technique you’ve chosen (automations to manage the off states) may very well be the only one (short of debugging the vera component).

configuration.yaml has:

envisalink:
  host: 192.168.1.200
  panel_type: DSC
  user_name: user
  password: password
  code: '123456'
  evl_version: 3
  keepalive_interval: 60
  zonedump_interval: 30
  panic_type: Police
  zones:
    1:
      name: 'motion'
      type: 'motion'
    9:
      name: 'front door'
      type: 'opening'
    10:
      name: 'back Door'
      type: 'opening'
  partitions:
    1:
      name: 'house2'

automation.yaml has:

- id: '1558836134896'
  alias: alert back door open
  trigger:
  - entity_id: binary_sensor.back_door
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      message: back door open
    service: notify.notifier

no issues with State since i restarted HA when i started this post.

You are only listing one automation. Do you have another to tell you the door was CLOSED?

i dont have another automation for closing because i only worry when it’s open. myself, i only open the back door once a week. so any other time it’s open would indicate a burglary.