openHASP-custom-component icon indicating copy to clipboard operation
openHASP-custom-component copied to clipboard

Openhasp does not work after HA restart.

Open adorobis opened this issue 1 year ago • 5 comments

Version of the custom_component

0.7.3

Configuration


hasp1:
  objects:
    # - obj: "p0b1"  # temperature label on all pages
      # properties:
        # "text": '{{ states("sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2") }}°C'
    - obj: "p0b1"  # time label on all pages
      properties:
        "text": '{{ states("sensor.time") }}'
    - obj: "p0b2"  # date label on all pages
      properties:
        "text": '{{ states("sensor.date") }}'
    - obj: "p0b3"
      properties:
        "text_color": "{% if -30 <= state_attr('openhasp.hasp_1','rssi') |int(0) %}green{% elif -31 > state_attr('openhasp.hasp_1','rssi') |int(0) >= -50 %}orange{% elif -51 > state_attr('openhasp.hasp_1','rssi') |int(0) >= -80 %}tomato{% else %}red{% endif %}"

    - obj: "p1b2"  # Temperatura południe
      properties:
        "text": '{% if states("sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2") != "unknown" and states("sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2") != "unavailable" %}{{ states("sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2") | round(1) }}°C{% else %}--{% endif %}'
        "bg_color": "{% if states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 0  %}blue{% elif 0 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 4 %}Aqua{% elif 4 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 15 %}Khaki{% elif 15 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 25 %}green{% elif 25 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 30 %}yellow{% else %}red{% endif %}"
        "bg_grad_color": "{% if states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 0  %}blue{% elif 0 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 4 %}Aqua{% elif 4 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 15 %}Khaki{% elif 15 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 25 %}green{% elif 25 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 30 %}yellow{% else %}red{% endif %}"
        "text_color": "{% if states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 0  %}#FFFFFF{% elif 0 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 4 %}#000000{% elif 4 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 15 %}#000000{% elif 15 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 25 %}#FFFFFF{% elif 25 < states('sensor.qubino_goap_zmnhbdx_flush_2_relays_temperature_2') |int(0) <= 30 %}#000000{% else %}#FFFFFF{% endif %}"
    - obj: "p1b3"  # Temperatura stacja pogodowa
      properties:
        "text": '{% if states("sensor.outdoor_temperature") != "unknown" and states("sensor.outdoor_temperature") != "unavailable" %}{{ states("sensor.outdoor_temperature") | round(1) }}°C{% else %}--{% endif %}'
        "bg_color": "{% if states('sensor.outdoor_temperature') |int(0) <= 0  %}blue{% elif 0 < states('sensor.outdoor_temperature') |int(0) <= 4 %}Aqua{% elif 4 < states('sensor.outdoor_temperature') |int(0) <= 15 %}Khaki{% elif 15 < states('sensor.outdoor_temperature') |int(0) <= 25 %}green{% elif 25 < states('sensor.outdoor_temperature') |int(0) <= 30 %}yellow{% else %}red{% endif %}"
        "bg_grad_color": "{% if states('sensor.outdoor_temperature') |int(0) <= 0  %}blue{% elif 0 < states('sensor.outdoor_temperature') |int(0) <= 4 %}Aqua{% elif 4 < states('sensor.outdoor_temperature') |int(0) <= 15 %}Khaki{% elif 15 < states('sensor.outdoor_temperature') |int(0) <= 25 %}green{% elif 25 < states('sensor.outdoor_temperature') |int(0) <= 30 %}yellow{% else %}red{% endif %}"
        "text_color": "{% if states('sensor.outdoor_temperature') |int(0) <= 0  %}#FFFFFF{% elif 0 < states('sensor.outdoor_temperature') |int(0) <= 4 %}#000000{% elif 4 < states('sensor.outdoor_temperature') |int(0) <= 15 %}#000000{% elif 15 < states('sensor.outdoor_temperature') |int(0) <= 25 %}#FFFFFF{% elif 25 < states('sensor.outdoor_temperature') |int(0) <= 30 %}#000000{% else %}#FFFFFF{% endif %}"
    - obj: "p1b4"  # Brama
      properties:
        "val": '{{ 1 if states("cover.brama") == "closed" else 0 }}'
        "text": '{{ "\uF2D3" if is_state("cover.brama", "closed") else "\uF2D4" | e }}'
        "bg_color": '{{ "Red" if is_state("cover.brama", "open") else "Green" | e }}'
        "bg_grad_color": '{{ "Red" if is_state("cover.brama", "open") else "Green" | e }}'
        "enabled": "{{ false if states('input_boolean.hasp1_locked') == 'on' else true }}"
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "cover.brama"
    - obj: "p1b5"  # Wszystkie światła
      properties:
        "val": '{{ 1 if states("group.all_lights") == "on" else 0 }}'
        "text": '{{ "\uE6E8" if is_state("group.all_lights", "on") else "\uE335" | e }}'
        "bg_color": '{{ "Gray" if is_state("group.all_lights", "off") else "Green" | e }}'
        "bg_grad_color": '{{ "Gray" if is_state("group.all_lights", "off") else "Green" | e }}'
        "enabled": "{{ false if states('input_boolean.hasp1_locked') == 'on' else true }}"
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "switch.all_lights"
    - obj: "p1b6"  # Światła - drzewa
      properties:
        "val": '{{ 1 if states("switch.qubino_goap_zmnhbdx_flush_2_relays_switch_2") == "on" else 0 }}'
        "text": '{{ "\uE406" if is_state("switch.qubino_goap_zmnhbdx_flush_2_relays_switch_2", "on") else "\uE406" | e }}'
        "bg_color": '{{ "Gray" if is_state("switch.qubino_goap_zmnhbdx_flush_2_relays_switch_2", "off") else "Green" | e }}'
        "bg_grad_color": '{{ "Gray" if is_state("switch.qubino_goap_zmnhbdx_flush_2_relays_switch_2", "off") else "Green" | e }}'
        "enabled": "{{ false if states('input_boolean.hasp1_locked') == 'on' else true }}"
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "switch.qubino_goap_zmnhbdx_flush_2_relays_switch_2"
    - obj: "p1b7"  # Światła - ogród front
      properties:
        "val": '{{ 1 if states("switch.outdoor_front_lights") == "on" else 0 }}'
        "text": '{{ "\uE8DD" if is_state("switch.outdoor_front_lights", "on") else "\uE8DD" | e }}'
        "bg_color": '{{ "Gray" if is_state("switch.outdoor_front_lights", "off") else "Green" | e }}'
        "bg_grad_color": '{{ "Gray" if is_state("switch.outdoor_front_lights", "off") else "Green" | e }}'
        "enabled": "{{ false if states('input_boolean.hasp1_locked') == 'on' else true }}"
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "switch.outdoor_front_lights"
    - obj: "p1b10"  # Pogoda ikona
      properties:
        "text": "{% if states('weather.home')  == 'clear_night'  %}\uE594{% elif states('weather.home')  == 'cloudy' %}\uE590{% elif states('weather.home')  == 'fog'  %}\uE591{% elif states('weather.home')  == 'lightning_rainy'  %}\uE67E{% elif states('weather.home')  == 'partlycloudy'  %}\uE595{% elif states('weather.home')  == 'pouring'  %}\uE596{% elif states('weather.home')  == 'rainy'  %}\uE597{% elif states('weather.home')  == 'snowy'  %}\uE598{% elif states('weather.home')  == 'snowy_rainy'  %}\uE67F{% else %}\uE599{% endif %}"
    - obj: "p1b11"  # Światła - taras
      properties:
        "val": '{{ 1 if states("switch.taras_lights") == "on" else 0 }}'
        "text": '{{ "\uEA47" if is_state("switch.taras_lights", "on") else "\uEA47" | e }}'
        "bg_color": '{{ "Gray" if is_state("switch.taras_lights", "off") else "Green" | e }}'
        "bg_grad_color": '{{ "Gray" if is_state("switch.taras_lights", "off") else "Green" | e }}'
        "enabled": "{{ false if states('input_boolean.hasp1_locked') == 'on' else true }}"
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "switch.taras_lights"
    - obj: "p1b12"  # Stan alarmu
      properties:
        "text": "{% if states('switch.alarm_armed') == 'off' %}\uEFC6{% else %}\uE33E{% endif %}"
        "text_color": "{% if states('group.allpersons')  == 'home' %}White{% elif states('switch.alarm_armed') == 'off' %}Green{% else %}Red{% endif %}"
        "bg_color": "{% if states('group.allpersons')  == 'not_home'  %}Gray{% elif states('switch.alarm_armed') == 'off' %}Green{% else %}Red{% endif %}"
        "bg_grad_color": "{% if states('group.allpersons')  == 'not_home'  %}Gray{% elif states('switch.alarm_armed') == 'off' %}Green{% else %}Red{% endif %}"
        "enabled": "{{ false if states('input_boolean.hasp1_locked') == 'on' else true }}"
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "switch.alarm_armed"
    - obj: "p2b4"  # Cover: refleksola
      properties:
        "val": >
            {% if (state_attr('cover.taras_dach','current_position') != none and states('cover.taras_refleksola') not in ['unavailable', 'unknown']) %}
            {{ state_attr('cover.taras_dach','current_position') | int(default=100) }}
            {%-endif %}
      event:
        "up":
          - service: cover.set_cover_position
            data:
              position: "{{ val | int }}"
            target:
              entity_id: cover.taras_dach
    - obj: "p2b9"  # Cover: refleksola
      properties:
        "val": >
            {% if (state_attr('cover.taras_refleksola','current_position') != none and states('cover.taras_refleksola') not in ['unavailable', 'unknown']) %}
            {{ state_attr('cover.taras_refleksola','current_position') | int(default=100) }}
            {%-endif %}
      event:
        "up":
          - service: cover.set_cover_position
            data:
              position: "{{ val | int }}"
            target:
              entity_id: cover.taras_refleksola
    - obj: "p2b5" # Pergola Switch
      properties:
        "val": '{{ 1 if is_state("light.taras_gora", "on") else 0 }}'
        # "text": '{{ "\uE6E8" if is_state("light.taras_gora", "on") else "\uE335" | e }}'
      event:
        "down":
          - service: homeassistant.toggle
            entity_id: "light.taras_gora"
    - obj: "p2b6" # Pergola Switch
      properties:
        "val": '{{ 1 if is_state("light.taras_gora", "on") else 0 }}'
        # "text": '{{ "\uE6E8" if is_state("light.taras_gora", "on") else "\uE335" | e }}'
      event:
        "down":
          - service: homeassistant.toggle
            entity_id: "light.taras_gora"
    - obj: "p2b7" # Półki Switch
      properties:
        "val": '{{ 1 if is_state("light.taras_channel_2", "on") else 0 }}'
        # "text": '{{ "\uE6E8" if is_state("light.taras_channel_2", "on") else "\uE335" | e }}'
      event:
        "down":
          - service: homeassistant.toggle
            entity_id: "light.taras_channel_2"
    - obj: "p2b8" # Półki Switch
      properties:
        "val": '{{ 1 if is_state("light.taras_channel_2", "on") else 0 }}'
        # "text": '{{ "\uE6E8" if is_state("light.taras_channel_2", "on") else "\uE335" | e }}'
      event:
        "down":
          - service: homeassistant.toggle
            entity_id: "light.taras_channel_2"
    - obj: "p2b11"  # Rain sensor Aquara
      properties:
        "text": '{{ "\uE597" if is_state("binary_sensor.water_leak_1_water_leak", "on") else "\uE599" | e }}'
        "bg_color": '{{ "Red" if is_state("binary_sensor.water_leak_1_water_leak", "on") else "Green" | e }}'
        "bg_grad_color": '{{ "Red" if is_state("binary_sensor.water_leak_1_water_leak", "on") else "Green" | e }}'
    - obj: "p3b11"  # Volume Down
      event:
        "down":
          - service: media_player.volume_down
            entity_id: "media_player.taras"
    - obj: "p3b19"  # Volume Up
      event:
        "down":
          - service: media_player.volume_up
            entity_id: "media_player.taras"
    - obj: "p3b5"  # Volume Level
      properties:
        "text": '{{ "\uE4C3 "+"--%" if (state_attr("media_player.taras", "volume_level") == none) else "\uE4C3 " + (state_attr("media_player.taras", "volume_level") * 100) | int(0) | string +"%" }}'
    - obj: "p3b16"  # Image: Radio Nowy Świat
      properties:
        "src": '{{ "L:/new.bin" if is_state("switch.nowyswiat_taras", "on") else "L:/new_off.bin" | e }}'
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "switch.nowyswiat_taras"
    - obj: "p3b7"  # Radio 357
      properties:
        "val": '{{ 1 if states("switch.radio357_taras") == "on" else 0 }}'
        "text": '{{ "\uE4C3" if is_state("switch.radio357_taras", "on") else "\uE4C3" | e }}'
        "bg_color": '{{ "Gray" if is_state("switch.radio357_taras", "off") else "Green" | e }}'
        "bg_grad_color": '{{ "Gray" if is_state("switch.radio357_taras", "off") else "Green" | e }}'
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "switch.radio357_taras"
    - obj: "p3b17"  # Image: Radio 357
      properties:
        "src": '{{ "L:/357.bin" if is_state("switch.radio357_taras", "on") else "L:/357_off.bin" | e }}'
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "switch.radio357_taras"
    - obj: "p3b12"  # Radio Baobab
      properties:
        "val": '{{ 1 if states("switch.baobab_taras") == "on" else 0 }}'
        "text": '{{ "\uE4C3" if is_state("switch.baobab_taras", "on") else "\uE4C3" | e }}'
        "bg_color": '{{ "Gray" if is_state("switch.baobab_taras", "off") else "Green" | e }}'
        "bg_grad_color": '{{ "Gray" if is_state("switch.baobab_taras", "off") else "Green" | e }}'
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "switch.baobab_taras"
    - obj: "p3b18"  # Image: Radio Baobab
      properties:
        "src": '{{ "L:/baobab.bin" if is_state("switch.baobab_taras", "on") else "L:/baobab_off.bin" | e }}'
      event:
        "up":
          - service: homeassistant.toggle
            entity_id: "switch.baobab_taras"
            
    - obj: "p4b6"  # Woda główny
      properties:
        "text": '{{ states("sensor.water_total") | round(0) | string + " m³" }} '
    - obj: "p4b7"  # Woda ogród
      properties:
        "text": '{{ states("sensor.water_garden_total") | round(0) | string + " m³"  }}'

Describe the bug

After restarting HA the Openhasp integration does not load configured entities. Example error message in the log below, there are multiple ones like that for each entity of the openhasp device. Interestingly after enabling debug log and restarting HA all works ok, no errors in the log. After disabling the debug log and restarting again is like below. Reloading the integration in the running HA makes the integration work again ok. Very confusing.

Debug log


2024-07-15 19:00:02.309 ERROR (MainThread) [custom_components.openhasp] Error adding entity openhasp.hasp1 for domain openhasp with platform openhasp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 598, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1361, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/openhasp/__init__.py", line 443, in async_added_to_hass
    await async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 182, in async_publish
    await mqtt_data.client.async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 635, in async_publish
    msg_info = self._mqttc.publish(topic, payload, qos, retain)
               ^^^^^^^^^^^
AttributeError: 'MQTT' object has no attribute '_mqttc'
2024-07-15 19:00:02.340 ERROR (MainThread) [custom_components.openhasp] Error adding entity openhasp.hasp2 for domain openhasp with platform openhasp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 598, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1361, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/openhasp/__init__.py", line 443, in async_added_to_hass
    await async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 182, in async_publish
    await mqtt_data.client.async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 635, in async_publish
    msg_info = self._mqttc.publish(topic, payload, qos, retain)
               ^^^^^^^^^^^
AttributeError: 'MQTT' object has no attribute '_mqttc'
2024-07-15 19:00:07.369 ERROR (MainThread) [homeassistant.components.light] Error adding entity light.hasp1_backlight for domain light with platform openhasp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 598, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1361, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/openhasp/light.py", line 326, in async_added_to_hass
    await async_publish(self.hass, cmd_topic, "backlight", qos=0, retain=False)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 182, in async_publish
    await mqtt_data.client.async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 644, in async_publish
    await self._async_wait_for_mid_or_raise(msg_info.mid, msg_info.rc)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 1200, in _async_wait_for_mid_or_raise
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected.
2024-07-15 19:00:07.372 ERROR (MainThread) [homeassistant.components.light] Error adding entity light.hasp1_moodlight for domain light with platform openhasp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 598, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1361, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/openhasp/light.py", line 468, in async_added_to_hass
    await async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 182, in async_publish
    await mqtt_data.client.async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 644, in async_publish
    await self._async_wait_for_mid_or_raise(msg_info.mid, msg_info.rc)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 1200, in _async_wait_for_mid_or_raise
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected.
2024-07-15 19:00:07.374 ERROR (MainThread) [homeassistant.components.light] Error adding entity light.hasp2_backlight for domain light with platform openhasp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 598, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1361, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/openhasp/light.py", line 326, in async_added_to_hass
    await async_publish(self.hass, cmd_topic, "backlight", qos=0, retain=False)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 182, in async_publish
    await mqtt_data.client.async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 644, in async_publish
    await self._async_wait_for_mid_or_raise(msg_info.mid, msg_info.rc)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 1200, in _async_wait_for_mid_or_raise
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected.
2024-07-15 19:00:07.376 ERROR (MainThread) [homeassistant.components.light] Error adding entity light.hasp2_moodlight for domain light with platform openhasp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 598, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1361, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/openhasp/light.py", line 468, in async_added_to_hass
    await async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 182, in async_publish
    await mqtt_data.client.async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 644, in async_publish
    await self._async_wait_for_mid_or_raise(msg_info.mid, msg_info.rc)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 1200, in _async_wait_for_mid_or_raise
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected.

adorobis avatar Jul 15 '24 17:07 adorobis

I've now even created an automation to reload openhasp 30 seconds after HA start. And it works. Looking at the error log above I have a suspission that openhasp intrgration tries to communicate to the MQTT broker before the connection to it is established by HA? And then it fails and does not try anymore. Btw, this might also explain why it works with the debug log on - it takes longer to load the openhasp integration and the MQTT integration is loaded by that time.

adorobis avatar Jul 15 '24 17:07 adorobis

Same problem here. Can you share an openhasp reload automation example?

pepe59 avatar Jul 15 '24 20:07 pepe59

automation example

alias: System - reload openhasp integration on HA start
description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: homeassistant.reload_config_entry
    target:
      device_id:
        - a33aa113b69e17fe97ceadcb7690c07e
        - 4c7796c8c47f6907734b66476bf7a5be
    data: {}
mode: single

You'll get the device id when selecting a hasp device from GUI editor

adorobis avatar Jul 16 '24 05:07 adorobis

Thanks, I'll include it in the automations.

pepe59 avatar Jul 16 '24 07:07 pepe59

Did an update a few days ago everything was still working. Lost power today and my screens aren't working. Thanks for providing a solution.

EDIT: I guess it wasn't my issue. It did not work for me.

I did see this in the DEBUG logs.

WARNING (MainThread) [homeassistant.helpers.frame] Detected code that calls async_forward_entry_setup for integration openhasp with title: wt32 and entry_id: 7a3ad312332sd3b58f42da3bfafef125f, during setup without awaiting async_forward_entry_setup, which can cause the setup lock to be released before the setup is done. This will stop working in Home Assistant 2025.1. Please report this issue.

bwente avatar Jul 24 '24 01:07 bwente

https://github.com/HASwitchPlate/openHASP-custom-component/pull/137 fixed the startup issue for me. No need to reload the config_entry anymore. So please try https://github.com/HASwitchPlate/openHASP-custom-component/releases/tag/0.7.4 and see if it helps you too.

Nevertheless it still throws an error as mentioned by @adorobis AttributeError: 'MQTT' object has no attribute '_mqttc' in the logs


Logger: custom_components.openhasp
Quelle: helpers/entity_platform.py:598
Integration: openHASP (Dokumentation, Probleme)
Erstmals aufgetreten: 17:41:18 (4 Vorkommnisse)
Zuletzt protokolliert: 17:41:18

Error adding entity openhasp.kueche for domain openhasp with platform openhasp
Error adding entity openhasp.bad for domain openhasp with platform openhasp
Error adding entity openhasp.buero for domain openhasp with platform openhasp
Error adding entity openhasp.kinderzimmer for domain openhasp with platform openhasp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 598, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1361, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/openhasp/__init__.py", line 443, in async_added_to_hass
    await async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 182, in async_publish
    await mqtt_data.client.async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 635, in async_publish
    msg_info = self._mqttc.publish(topic, payload, qos, retain)
               ^^^^^^^^^^^
AttributeError: 'MQTT' object has no attribute '_mqttc'

TNTLarsn avatar Aug 06 '24 15:08 TNTLarsn

Released 0.7.4 please test

fvanroie avatar Aug 06 '24 21:08 fvanroie

I've just rebooted HA and the integration seems to work ok now. Hope this will stay like that :) Many thanks!

adorobis avatar Aug 08 '24 15:08 adorobis

great , thanks

fvanroie avatar Aug 08 '24 15:08 fvanroie

Seems the issue is back (or similar). I'm now on HA 2024.9.0, openhasp 0.7.5 and see the following error after HA restart:

2024-09-04 23:40:13.800 ERROR (MainThread) [custom_components.openhasp] Error adding entity openhasp.hasp1 for domain openhasp with platform openhasp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 595, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 909, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1365, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/openhasp/__init__.py", line 445, in async_added_to_hass
    await async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 182, in async_publish
    await mqtt_data.client.async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 635, in async_publish
    msg_info = self._mqttc.publish(topic, payload, qos, retain)
               ^^^^^^^^^^^
AttributeError: 'MQTT' object has no attribute '_mqttc'
2024-09-04 23:40:13.820 ERROR (MainThread) [custom_components.openhasp] Error adding entity openhasp.hasp2 for domain openhasp with platform openhasp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 595, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 909, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1365, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/openhasp/__init__.py", line 445, in async_added_to_hass
    await async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 182, in async_publish
    await mqtt_data.client.async_publish(
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 635, in async_publish
    msg_info = self._mqttc.publish(topic, payload, qos, retain)
               ^^^^^^^^^^^
AttributeError: 'MQTT' object has no attribute '_mqttc'

This looks like exactly the same error message as when I have raised it in July. Similarly like before it starts working ok after reloading the integration.

adorobis avatar Sep 05 '24 09:09 adorobis

If you have the possibility to test something, it requires the replacement of a file in the installation to give it a test:

https://github.com/HASwitchPlate/openHASP-custom-component/pull/149#issuecomment-2333550266

If you can replace the /root/config/custom_components/openhasp/__init__.py with the one from this PR and see if it fixes your issue.

xNUTx avatar Sep 06 '24 08:09 xNUTx

Yes, it did the trick. No error message anymore and all works after HA restart. Many thanks! Is it going to be part of next release?

adorobis avatar Sep 06 '24 08:09 adorobis

Yes, it did the trick. No error message anymore and all works after HA restart. Many thanks! Is it going to be part of next release?

That depends on @dgomes and @fvanroie :)

But I'm happy I found the way to fix this issue. With thanks to @dgomes who pointed me in the right direction.

xNUTx avatar Sep 06 '24 09:09 xNUTx

So the 0.7.6 version is here and all works great again. Many thanks!

adorobis avatar Sep 07 '24 12:09 adorobis