Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Since #36479 mqtt sensors are set to 'unavailable' on HA restart #37209

Closed
VDRainer opened this issue Jun 28, 2020 · 2 comments · Fixed by #37230
Closed

Since #36479 mqtt sensors are set to 'unavailable' on HA restart #37209

VDRainer opened this issue Jun 28, 2020 · 2 comments · Fixed by #37230
Assignees
Milestone

Comments

@VDRainer
Copy link
Contributor

VDRainer commented Jun 28, 2020

The problem

CC @definitio
In beta 0.112 on HA restart, mqtt sensor states go to unavailable.
Looks like since #36479 the mqtt connection is disconnected before HA shutdown is complete and so mqtt sensor states are stored 'unavailable'.

Environment

  • Home Assistant Core release with the issue: 0.112.0b2
  • Last working Home Assistant Core release (if known): 0.111.4
  • Operating environment (OS/Container/Supervised/Core): Ubuntu 18.04, Python 3.8.3 venv
  • Integration causing this issue: mqtt sensor
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/sensor.mqtt/

Problem-relevant configuration.yaml

The following automation sends a notification
"There are unavailable ubuntu updates available."
on HA restart before HA shutdown is complete

sensor:
  - platform: mqtt
    name: tpad_os_updates
    state_topic: 'home/sensors/TPAD/os_updates'

automation:
  - alias: Update notification OS TPAD
    initial_state: true
    trigger:
      - platform: state
        entity_id: sensor.tpad_os_updates
    condition:
      - condition: template
        value_template: "{{ states('sensor.tpad_os_updates') != '0/0' }}"
    action:
      - service: notify.mobile_app_rainer
        data_template: 
          title: "TPAD OS Updates"
          message: "There are {{ states.sensor.tpad_os_updates.state }} ubuntu updates available."

Temporary fix:

      - condition: template
        value_template: "{{ states('sensor.tpad_os_updates') != '0/0' and states('sensor.tpad_os_updates') != 'unavailable' }}"

Traceback/Error logs

Additional information

https://discord.com/channels/330944238910963714/427516175237382144/726724658258247711

@definitio
Copy link
Contributor

I'll look into it.

@balloob balloob added this to the 0.112.0 milestone Jun 28, 2020
@balloob
Copy link
Member

balloob commented Jun 28, 2020

Can be easily fixed by checking inside async_mqtt_connect if hass.is_running before writing the state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants