anotherjulien / MyHOME

MyHOME integration for Home-Assistant
GNU Affero General Public License v3.0
137 stars 54 forks source link

Problems loading lights after 2022.8 #59

Open teejay-87 opened 2 years ago

teejay-87 commented 2 years ago

Hello,

Since update to 2022.8, MyHome integration has problem loading any light (appliances configured as switch works fine, interestingly). Lights do not load on HA startup, but they do if I reload the integration from the Settings panel.

There is a log about deprecated methods:


Source: helpers/frame.py:77 
First occurred: 23 agosto 2022, 00:43:56 (3 occurrences) 
Last logged: 23 agosto 2022, 00:43:56

Detected integration that uses deprecated `async_get_registry` to access device registry, use async_get instead. Please report issue to the custom integration author for myhome using this method at custom_components/myhome/__init__.py, line 89: device_registry = await hass.helpers.device_registry.async_get_registry()
Detected integration that uses deprecated `async_get_registry` to access entity registry, use async_get instead. Please report issue to the custom integration author for myhome using this method at custom_components/myhome/__init__.py, line 159: entity_registry = await hass.helpers.entity_registry.async_get_registry()
Detected integration that uses deprecated `async_get_registry` to access device registry, use async_get instead. Please report issue to the custom integration author for myhome using this method at custom_components/myhome/__init__.py, line 160: device_registry = await hass.helpers.device_registry.async_get_registry()```
teejay-87 commented 2 years ago

Updating my installation to use master branch, the log about deprecation disappeared, but the problem remains, albeit symptoms changed.

In particular, at HA starts, lights appear (instead of not being present at all) but do not function. This at least prevent them from being removed from HomeKit devices every time I restart HA. Then, reloading the integration makes them work fine.

I workarounded the problem by using this automation:

alias: Reload myHome when Home Assistant starts
description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: homeassistant.reload_config_entry
    data:
      entry_id: <my_home_entity_id>
mode: single
viperxeno commented 2 years ago

I have the same error after update HA to 2022.8.0. need for fix bug

caiosweet commented 2 years ago

I have the same error after update HA to 2022.8.0. need for fix bug

Read here. why the integration fails to load correctly.

caiosweet commented 2 years ago

Updating my installation to use master branch, the log about deprecation disappeared, but the problem remains, albeit symptoms changed.

In particular, at HA starts, lights appear (instead of not being present at all) but do not function. This at least prevent them from being removed from HomeKit devices every time I restart HA. Then, reloading the integration makes them work fine.

I workarounded the problem by using this automation:

alias: Reload myHome when Home Assistant starts
description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: homeassistant.reload_config_entry
    data:
      entry_id: <my_home_entity_id>
mode: single

little correction. if you use entity, entity_id should be used and not entry_id. :)

entity_id: <my_home_entity_id>

alessandro-lac commented 2 years ago

I tried both automation @caiosweet and the one linked in the community, but it looks like they do not properly work. I also tried to increase the delay or even run the automation twice. Still, some entities are not working after a restart. If I reload it manually, everything works fine.

description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - delay:
      hours: 0
      minutes: 1
      seconds: 30
      milliseconds: 0
  - service: hassio.addon_stdin
    data:
      addon: myhome
      input: reload
mode: single

Any suggestion?

viperxeno commented 2 years ago

I tried both automation @caiosweet and the one linked in the community, but it looks like they do not properly work. I also tried to increase the delay or even run the automation twice. Still, some entities are not working after a restart. If I reload it manually, everything works fine.

description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - delay:
      hours: 0
      minutes: 1
      seconds: 30
      milliseconds: 0
  - service: hassio.addon_stdin
    data:
      addon: myhome
      input: reload
mode: single

Any suggestion?

I have same problem... it need reload manually

caiosweet commented 2 years ago

I tried both automation @caiosweet and the one linked in the community, but it looks like they do not properly work. I also tried to increase the delay or even run the automation twice. Still, some entities are not working after a restart. If I reload it manually, everything works fine.

description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - delay:
      hours: 0
      minutes: 1
      seconds: 30
      milliseconds: 0
  - service: hassio.addon_stdin
    data:
      addon: myhome
      input: reload
mode: single

Any suggestion?

I have same problem... it need reload manually

A suggestion is to check if any entity is unavailable at startup. states('binary_sensor.pir_sala') in ['unavailable', 'unknown']

This is my test automation, to be refined, where in addition I have also added the thermostat status request, so as not to wait for the central unit to send the request too late (usually every 15 minutes)

automation:
  - alias: "Timer Richiesta Energia"
    initial_state: true
    max_exceeded: silent
    trigger:
      - platform: homeassistant
        event: start
        id: "avvio"
      - platform: time_pattern
        hours: "/2"
    variables:
      tot_zone: 4
    action:
      - choose:
          - conditions: "{{ states('sensor.temp_quadro')|int(0)<= 0 or 
              states('binary_sensor.pir_sala') in ['unavailable', 'unknown'] }}" 
            sequence:
              - service: homeassistant.reload_config_entry
                data:
                  entity_id: light.luce_bagno
                  # area_id: 
                  # device_id:
                  # entry_id: c25758ebba2003c3586f9b8d92558fce

      - service: myhome.start_sending_instant_power
        data:
          duration: 125
          entity_id: sensor.consumo_generale_power
      - delay:
          milliseconds: 500
      - service: myhome.sync_time
        data: {}
      - delay:
          milliseconds: 500
      - service: myhome.send_message
        data:
          message: "*#1*0##" # All Status

      - choose:
          - conditions: "{{ 'avvio' in trigger.id }}"
            sequence:
              - alias: Repeat the sequence UNTIL the conditions are true
                repeat:
                  sequence:
                    - delay:
                        seconds: 2
                    - service: myhome.send_message
                      data:
                        message: "*4*311*#{{repeat.index}}##" #richiesta stato probe n
                  until:
                    - condition: template
                      value_template: "{{ repeat.index == tot_zone }}"
teejay-87 commented 2 years ago

@viperxeno @alessandro-lac Use my automation. It works fine. To find the entry_id, please search in config/.storage/core.config_entries file.

@caiosweet entry_id is right, the <my_home_entity_id> is wrong (should've been <my_home_entry_id>).

caiosweet commented 2 years ago
  - service: hassio.addon_stdin
    data:
      addon: myhome
      input: reload

I don't think this is the right way. it is not an addon but an integration. The right way is to use homeassistant.reload_config_entry

              - service: homeassistant.reload_config_entry
                data:
                  entity_id: light.luce_bagno # any myhome entity in your system
                  # area_id: 
                  # device_id:
                  # entry_id: c25758ebba2003c3586f9b8d92558fce # or your entry_id in your system

@teejay-87 yes! There are 4 ways to reload. I use entities, because in the past canceling the integration, and the entry_id changed.

teejay-87 commented 2 years ago

@teejay-87 yes! There are 4 ways to reload. I use entities, because in the past canceling the integration, and the entry_id changed.

Ok! Didn't know that you can use any entity of the integration to trigger its reloading!

alessandro-lac commented 2 years ago

Thanks for the inputs, I actually had to do a mix of both to make it work 😇

I took and edit your automation @caiosweet , super cool... but had to place the entry_id, because with entity_id I kept having an error: There were no matching config entries to reload .

In the end my automation is the following:

alias: Complex MyHome Reboot
description: ""
trigger:
  - platform: homeassistant
    event: start
    id: avvio
  - platform: time_pattern
    hours: /2
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ state_attr('climate.living_room',
              'current_temperature')|int(0)<= 0 or 
              states('light.first_floor_balcony_light') in ['unavailable',
              'unknown'] }}
        sequence:
          - service: homeassistant.reload_config_entry
            data:
              entry_id: 00aa000000adfa3452455c8c5
  - delay:
      milliseconds: 500
  - service: myhome.sync_time
    data: {}
  - delay:
      milliseconds: 500
  - service: myhome.send_message
    data:
      message: "*#1*0##"
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ 'avvio' in trigger.id }}"
        sequence:
          - alias: Repeat the sequence UNTIL the conditions are true
            repeat:
              sequence:
                - delay:
                    seconds: 2
                - service: myhome.send_message
                  data:
                    message: "*4*0*{{repeat.index}}##"
              until:
                - condition: template
                  value_template: "{{ repeat.index == tot_zone }}"
initial_state: true
max_exceeded: silent
variables:
  tot_zone: 2

Hope this helps others 💪

viperxeno commented 2 years ago

Hi @alessandro-lac , what is the message # 1 0 ## and the message 4 0 * {{repeat.index}} ## for?

And then...

variables: tot_zone: 2 what is it for in automation? Thanks

alessandro-lac commented 2 years ago

Hi, sorry for my late reply, this is what I understood from @caiosweet integration: a message with * # 1 * 0 ## I believe it triggers MyHome to send an update for all connected devices, while * 4 * 0 * {{repeat.index}} ## check for the Thermostat status of the 2 zones I have. That is also why tot_zone is 2, because it asks for the status of both zones.