home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.94k stars 29.03k forks source link

SNMP blocks Home Assistant startup if device is not available on the network at startup. #118874

Open jasonwragg opened 1 month ago

jasonwragg commented 1 month ago

The problem

If a monitored device is not available during the Home Assistant startup hangs until it is available again.

What version of Home Assistant Core has the issue?

2024.5.5

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

SNMP

Link to integration documentation on our website

https://www.home-assistant.io/integrations/snmp/

Diagnostics information

No response

Example YAML snippet

sensor:
  - platform: snmp
    host: 192.168.1.50
    baseoid: 1.3.6.1.2.1.25.1.1.0
    community: public
    name: 'Pithos Uptime'
    value_template: >-
      {% set time = (value | int) | int %}
      {% set minutes = ((time % 360000) / 6000) | int(0) %}
      {% set hours = ((time % 8640000) / 360000) | int(0) %}
      {% set days = (time / 8640000) | int(0) %}
        {%- if time < 60 -%}
          Less then 1 min
          {%- else -%}
          {%- if days > 0 -%}
            {{ days }}d
          {%- endif -%}
          {%- if hours > 0 -%}
            {%- if days > 0 -%}
              {{ ' ' }}
            {%- endif -%}
            {{ hours }}hr
          {%- endif -%}
          {%- if minutes > 0 -%}
            {%- if days > 0 or hours > 0 -%}
              {{ ' ' }}
            {%- endif -%}
            {{ minutes }}min
          {%- endif -%}
        {%- endif -%}

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.2.1.1.5.0
    name: 'Pithos Name'

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.3.1.9.1
    name: 'Pithos Disk1 State'

  - platform: snmp
    host: 192.168.1.37
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.3.1.9.2
    name: 'Pithos Disk2 State'

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.3.1.9.3
    name: 'Pithos Disk3 State'
  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.3.1.9.4
    name: 'Pithos Disk4 State'

  - platform: snmp
    host: 192.168.1.50
    community: public
    unit_of_measurement: "c"
    baseoid: 1.3.6.1.4.1.4526.22.3.1.10.1
    name: 'Pithos Disk1 Temp' 

  - platform: snmp
    host: 192.168.1.50
    community: public
    unit_of_measurement: "c"
    baseoid: 1.3.6.1.4.1.4526.22.3.1.10.2
    name: 'Pithos Disk2 Temp' 

  - platform: snmp
    host: 192.168.1.50
    community: public
    unit_of_measurement: "c"
    baseoid: 1.3.6.1.4.1.4526.22.3.1.10.3
    name: 'Pithos Disk3 Temp' 

  - platform: snmp
    host: 192.168.1.50
    community: public
    unit_of_measurement: "c"
    baseoid: 1.3.6.1.4.1.4526.22.3.1.10.4
    name: 'Pithos Disk4 Temp' 

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.3.1.7.1
    name: 'Pithos Disk1 Capacity'  
    value_template: >-
        {% set by = ( value | int) | int %}
        {% set kb = (by / 1024) | int(0) %}
        {% set mb = (kb / 1024) | int(0) %}
        {% set gb = (mb / 1024) | int(0) %}
        {% set tb = (gb / 1024) | int(0) %}
        {% if tb > 1 %}
        {{ tb }} TB
        {% elif gb > 1 %}
        {{ gb }} GB
        {% elif mb > 1 %}
        {{ mb }} MB
        {% endif %}

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.3.1.7.2
    name: 'Pithos Disk2 Capacity'  
    value_template: >-
        {% set by = ( value | int) | int(0) %}
        {% set kb = (by / 1024) | int(0) %}
        {% set mb = (kb / 1024) | int(0) %}
        {% set gb = (mb / 1024) | int(0) %}
        {% set tb = (gb / 1024) | int(0) %}
        {% if tb > 1 %}
        {{ tb }} TB
        {% elif gb > 1 %}
        {{ gb }} GB
        {% elif mb > 1 %}
        {{ mb }} MB
        {% endif %}

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.3.1.7.3
    name: 'Pithos Disk3 Capacity'  
    value_template: >-
        {% set by = ( value | int) | int(0) %}
        {% set kb = (by / 1024) | int(0) %}
        {% set mb = (kb / 1024) | int(0) %}
        {% set gb = (mb / 1024) | int(0) %}
        {% set tb = (gb / 1024) | int(0) %}
        {% if tb > 1 %}
        {{ tb }} TB
        {% elif gb > 1 %}
        {{ gb }} GB
        {% elif mb > 1 %}
        {{ mb }} MB
        {% endif %}

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.3.1.7.4
    name: 'Pithos Disk4 Capacity'  
    value_template: >-
        {% set by = ( value | int) | int(0) %}
        {% set kb = (by / 1024) | int(0) %}
        {% set mb = (kb / 1024) | int(0) %}
        {% set gb = (mb / 1024) | int(0) %}
        {% set tb = (gb / 1024) | int(0) %}
        {% if tb > 1 %}
        {{ tb }} TB
        {% elif gb > 1 %}
        {{ gb }} GB
        {% elif mb > 1 %}
        {{ mb }} MB
        {% endif %}

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.4.1.2.1
    name: 'Pithos Fan RPM'  

  - platform: snmp
    host: 192.168.1.50
    community: public
    unit_of_measurement: "c"
    baseoid: 1.3.6.1.4.1.4526.22.5.1.2.1
    name: 'Pithos Temp Value'  

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.7.1.4.1
    name: "Pithos Volume Status"

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.7.1.5.1
    name: 'Pithos Volume Size Actual'

  - platform: snmp
    host: 192.168.1.50
    community: public
    baseoid: 1.3.6.1.4.1.4526.22.7.1.6.1
    name: 'Pithos Volume Free Actual'

"

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 month ago

Hey there @nmaggioni, mind taking a look at this issue as it has been labeled with an integration (snmp) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `snmp` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign snmp` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


snmp documentation snmp source (message by IssueLinks)

nmaggioni commented 1 month ago

As far as I remember this is the usual behavior for unreachable network devices. In my testing I see that once the default timeout is reached the integration is marked as failed, an error is logged, but startup completes anyway. Does your instance get indefinitely stuck instead?

jasonwragg commented 1 month ago

Yes it seems to block everything else from loading and never times out.

nmaggioni commented 1 month ago

I tested the config you posted and startup completes correctly (it takes ~1min due to timeouts, but it finishes). Please post your logs and possibly your full config so we can check if there's anything else that's going haywire.

You also have a lone 192.168.1.37 between your sensors (Pithos Disk2 State), I suppose that's meant to point at 192.168.1.50 like the others?

jasonwragg commented 1 month ago

192.168.1.37 is my other NAS but that was up at the time. It should be in a different file.

I'm not at home at the moment, i'll post later when I'm back.