HA Startup isse with Sonos One speakers

I’ve had an issue for a long time where HA will not restart successfully, requiring me to log in with SSH, manually stop the HA service, wait 2 minutes for it to report stopped, and then start it again.

The service status report looks like this:

Jun 02 14:00:57 aml hass[14549]: AttributeError: 'NoneType' object has no attribute 'transport_id'
Jun 02 14:00:58 aml hass[14549]: 2020-06-02 14:00:58 ERROR (Thread-21) [pychromecast.socket_client] [192.168.0.72:8009] Failed to connect. No retries.
Jun 02 14:00:58 aml hass[14549]: 2020-06-02 14:00:58 ERROR (Thread-14) [pychromecast.socket_client] [192.168.0.71:8009] Failed to connect. No retries.
Jun 02 14:00:59 aml hass[14549]: 2020-06-02 14:00:59 ERROR (Thread-17) [pychromecast.controllers] Exception thrown when calling cast status listener
Jun 02 14:00:59 aml hass[14549]: Traceback (most recent call last):
Jun 02 14:00:59 aml hass[14549]:   File "/srv/homeassistant/lib/python3.6/site-packages/pychromecast/socket_client.py", line 1048, in _report_status
Jun 02 14:00:59 aml hass[14549]:     listener.new_cast_status(self.status)
Jun 02 14:00:59 aml hass[14549]:   File "/srv/homeassistant/lib/python3.6/site-packages/pychromecast/socket_client.py", line 381, in new_cast_status
Jun 02 14:00:59 aml hass[14549]:     new_channel = self.destination_id != cast_status.transport_id
Jun 02 14:00:59 aml hass[14549]: AttributeError: 'NoneType' object has no attribute 'transport_id'

The IP addresses specified in the error messages (192.168.0.71 and .72) are my Sonos One speakers, which I know appear to have Chromecast capabilties to many apps, but they do not - it’s an illusion.
After this error, HA startup freezes forever, and needs the manual stop/restart.
But this error does not happen all of the time. Sometimes at random HA will restart successfully, and in fact it tends to restart successfully if several restarts in a row are needed because other devices don’t initialize correctly.

can you share your automation?
There’s something about transport_id flagged up on your first line.
If you’ve set up something to run at HA startup, be aware that the status may not yet be available
Depending on what you’re trying to achieve, either cater for the fact that the state/entity may not yet be available, or add a wait

Thanks. I don’t have any automations that trigger on startup
Since this error and freeze on restart only happens some of the time, it may be a race condition with something in the HA startup. Is there some way I can figure out where that is and insert a delay in the startup? The fact that pychromecast is identified as the source of the error would seem to indicate that the problem may be in the initialization of that module. Could I delay that?

OK. In that case, do you use template sensors? There is probably a sensor that is not available at startup and as a result the template_sensor fails…
Hopefully the transport_id gives you a clue…

I have one template sensor that looks like this:

  - platform: template
    sensors:
      nestprotectok:
        value_template: >-
          {{ not is_state('sensor.hallway_nest_protect_co_status', 'Ok')
            or not is_state('sensor.hallway_nest_protect_smoke_status', 'Ok')
            or not is_state('sensor.hallway_nest_protect_battery_health', 'Ok')
            or not is_state('sensor.hallway_nest_protect_color_status', 'green')
            or not is_state('binary_sensor.hallway_nest_protect_online', 'on') }}

But I’m not sure how that would cause the transport_id error, or why it would report the error on the pychromecast module.
How would the transport_id give me a clue?

sorry it must be something else then. I think I’ve overreacted on the transport_id which is probably something within the pychromecast program.
Can you confirm if you’re on home assistant or on assistant core?
Also which version are you on?