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.79k stars 28.93k forks source link

Can Trådfri integration be made to automatically recover connection? #86045

Open larsalthof opened 1 year ago

larsalthof commented 1 year ago

The problem

The Trådfri gateway from Ikea is notoriously flaky, as evidenced by the know issue regarding this. (Error 115)

I have noticed that Homekit can automatically recover connection most of the time, and all the time if the gateway is restarted. Homebridge will recover if it is restarted, without the need to restart the gateway.

Would it be possible for the Trådfri integration to automatically attempt to re-authenticate if it experienced connection issues?

What version of Home Assistant Core has the issue?

2022.11.5

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Ikea Tradfri

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

tradfri documentation tradfri source

BonnyLindberg commented 1 year ago

I gave up on this and have found that there are two scenarios that Trådfri enters when it gets unresponsive. It is not an optimal way of solving it but I got fed up that I'm not able to turn on an of lamps and that my automations got stuck due to that I was not able to read states from my entities.

Scenario 1:

Light entities enters state: unknown, none or unavailable. Choose one entity that you want to have as verification entity. I also use this for some other integrations to make sure that they get restarted when they stop working. Please note that the script for restart is below in this text. For this scenario I made this automation:

- id: Tradfri restart
  alias: Trådfri restart
  initial_state: true
  trigger:
    - platform: template
      value_template: >
        {% if ((states('light.garderob_uppe_varmvit_lampa') == 'unknown') or (states('light.garderob_uppe_varmvit_lampa') == 'none') or (states('light.garderob_uppe_varmvit_lampa') == 'unavailable')) %}
          true
        {% else %}
          false
        {% endif %}      
      for: 00:05:00
  action:
  - service: script.starta_om_tradfri

Scenario 2: Trådfri is working but state is not updated for entities. First select one entity as your verification entity. Preferably it is a lamp in a wardrobe that is ok to turn on and of at a regular pattern for 1 second. Please note that the script for restart is below in this text. For this scenario I made this automation.

- id: Restart Trådfri new
  alias: Restart Trådfri new
  initial_state: true
  trigger:
    - platform: time_pattern
      minutes: "/5"
    - entity_id: alarm_control_panel.verisure_alarm
      to: disarmed
      platform: state
  action:
    - choose:
        - conditions: 
            - condition: template
              value_template: "{{ is_state('light.garderob_uppe_varmvit_lampa', 'on') }}"
          sequence:
            - service: light.turn_off
              data:
                entity_id: light.garderob_uppe_varmvit_lampa
            - delay:
                seconds: 1
            - condition: "{{ is_state('light.garderob_uppe_varmvit_lampa', 'on') }}"
            - service: script.turn_on
              target:
                entity_id: script.starta_om_tradfri
        - conditions: 
            - condition: template
              value_template: "{{ is_state('light.garderob_uppe_varmvit_lampa', 'off') }}"
          sequence:
            - service: light.turn_on
              data:
                entity_id: light.garderob_uppe_varmvit_lampa
            - delay:
                seconds: 1
            - choose:
                - conditions: 
                    - condition: template
                      value_template: "{{ is_state('light.garderob_uppe_varmvit_lampa', 'on') }}"
                  sequence:
                    - service: light.turn_off
                      data:
                        entity_id: light.garderob_uppe_varmvit_lampa
                - conditions: 
                    - condition: template
                      value_template: "{{ is_state('light.garderob_uppe_varmvit_lampa', 'off') }}"
                  sequence:
                    - service: light.turn_off
                      data:
                        entity_id: light.garderob_uppe_varmvit_lampa
                    - service: script.turn_on
                      target:
                        entity_id: script.starta_om_tradfri

Both automations call the below script:

starta_om_tradfri:
  alias: "Starta om Trådfri"
  sequence:
    - service: homeassistant.reload_config_entry
      data:
        entry_id: 1103634c6fdc438fa50bc9a58078e8d1
      target:
        entity_id: light.badrum_nere_spot_med_vitt_spektrum_2

I hope that this temporary solution will help some of you that got fed up with that it is not working as it should.

Mariusthvdb commented 1 year ago

there is an actual loggin to trigger on, when Tradfri returns 'Keep-alive failed'

I've documented in https://github.com/home-assistant/core/issues/85254#issuecomment-1469727156 how to use that, and also keep some stats on how often it happens.

works fine (even being a hacky fix), and still hoping devs will see a way to bring Tradfri back to being a stable integration (which it was until January...)

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Mariusthvdb commented 1 year ago

Keep, still relevant....

Scherm­afbeelding 2023-07-07 om 11 56 22
issue-triage-workflows[bot] commented 9 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

lutzky commented 9 months ago

Still relevant, definitely keeps happening to me.

issue-triage-workflows[bot] commented 6 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Mariusthvdb commented 6 months ago

Keep

dimafemabo commented 5 months ago

Yes, definitely keep, this is an ongoing issue

issue-triage-workflows[bot] commented 2 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Mariusthvdb commented 2 months ago

I've stopped using this integration because of the issue (moved all to Homekit devices on a Dirigera which is 100% rock solid) , so wont pursue any further here. Please anyone take over if so required