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
70k stars 29.08k forks source link

SamsungTV integration re discover TV any time after reboot #64465

Closed landaisbenj closed 2 years ago

landaisbenj commented 2 years ago

The problem

HA discover my samsungtv (i just have one), and so i could add the integration. But after every restart, HA want to add my tv every time.. (with translation error).

image

I can ignore, but why this... [EDIT] After adding twice, i have this after rebooting: image

What version of Home Assistant Core has the issue?

core-2021.12.10

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

samsungtv

Link to integration documentation on our website

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

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

Hey there @escoand, @chemelli74, mind taking a look at this issue as it has been labeled with an integration (samsungtv) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


samsungtv documentation samsungtv source (message by IssueLinks)

chemelli74 commented 2 years ago

We can check what happens in debug logs; add the following to configuration.yaml , restart HA, and post the log:

logger:
  default: warning
  logs:
    homeassistant.components.samsungtv: debug
    samsungtvws: debug
    samsungctl: debug

Note: it is better to drag the log into the comment (which will add it as an attachment) and not copy paste as it is hard to read logs in GitHub.

Simone

landaisbenj commented 2 years ago

Ok. Should i have suppress integration before ?

landaisbenj commented 2 years ago

home-assistant.log

I think it's good like this !

chemelli74 commented 2 years ago

Man, you have a log full of errors of any kind ;-) I think you should focus and fix your installation to clean them out.

About Samsung, remove the custom component:

2022-01-19 21:34:52 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration samsungtv_custom which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

I would also remove all configured and ignored SamsungTv, delete the auth in the TV menu, restart HA so to start from a clean situation:

2022-01-19 21:35:06 DEBUG (SyncWorker_6) [homeassistant.components.samsungtv] Access denied in getting remote object

Simone

landaisbenj commented 2 years ago

Yes I know. But I don’t know how 😭 especially for some like this:

2022-01-19 21:55:23 ERROR (MainThread) [snitun.client.client_peer] Challenge/Response error with SniTun server (0 bytes read on a total of 32 expected bytes)
2022-01-19 21:55:23 ERROR (MainThread) [hass_nabucasa.remote] Connection problem to snitun server
2022-01-19 21:55:33 ERROR (MainThread) [aiohttp.server] Error handling request

I take your comment. And repost here.

landaisbenj commented 2 years ago

Ok so, i'm like this : image for this log at start :
home-assistant.log I can try to re add the integration ?

chemelli74 commented 2 years ago

Quite strange the translation error, but yes try to add the integration confirming the configure

Simone

landaisbenj commented 2 years ago

Yes, we talk about this here :

https://github.com/home-assistant/core/issues/59249#issue-1046571582

So, I add the integration, confirmed in the tv and restart. Seems not discovered anymore 👍

chemelli74 commented 2 years ago

#59249 (comment)

Selected language is ?

So, I add the integration, confirmed in the tv and restart. Seems not discovered anymore 👍

Nice!

landaisbenj commented 2 years ago

Selected language is ?

French

landaisbenj commented 2 years ago

Ok, after some day, i have this appear on my notif panel 👍

image

Did you know if it's a bug ?

chemelli74 commented 2 years ago

Ok, after some day, i have this appear on my notif panel 👍

Did you know if it's a bug ?

If you try to configure, what happens ?

Simone

landaisbenj commented 2 years ago

Desapear 🤨

chemelli74 commented 2 years ago

Desapear 🤨

humm, can you share the log ?

djansen1987 commented 2 years ago

Same issue, also the tv keeps asking for approval. This happens on 3 of my samsung screens

image

(this wil stop ofcourse when you click deny (weiger))

chemelli74 commented 2 years ago

@landaisbenj , @djansen1987 do you mind updating to 2022.2.0b5 and then

Thx,

Simone

landaisbenj commented 2 years ago

Ok so i'm in now : image

Have this : image

This log : home-assistant.log

And i think, this is diagnostics ? config_entry-samsungtv-d60f4b349f3570c2a46676978086bd5a.json.txt image

djansen1987 commented 2 years ago

I don't see that option to download the logs image

landaisbenj commented 2 years ago

Maybe because you are not in 2022.2.0b5

chemelli74 commented 2 years ago

This log : home-assistant.log

And i think, this is diagnostics ? [config_entry-samsungtv-d60f4b349f3570c2a46676978086bd5a.json.txt]

Seems the token is not saved here for some reason. So can you confirm that TV is working right after adding it to HA, but at next reboot you get again a discovery?

Simone

djansen1987 commented 2 years ago

That is what i am seeing as behaviour

This log : home-assistant.log And i think, this is diagnostics ? [config_entry-samsungtv-d60f4b349f3570c2a46676978086bd5a.json.txt]

Seems the token is not saved here for some reason. So can you confirm that TV is working right after adding it to HA, but at next reboot you get again a discovery?

Simone

djansen1987 commented 2 years ago

Maybe because you are not in 2022.2.0b5

Missed the part on asking me to update, i am on: core-2021.12.10 supervisor-2022.01.1 not comfortable at the moment upgrading to beta

landaisbenj commented 2 years ago

This log : home-assistant.log And i think, this is diagnostics ? [config_entry-samsungtv-d60f4b349f3570c2a46676978086bd5a.json.txt]

Seems the token is not saved here for some reason. So can you confirm that TV is working right after adding it to HA, but at next reboot you get again a discovery?

Simone

I can change volume with ha on the TV. So tv work fine with ha. Maybe it’s because it’s an old model ? (2015). But if if reboot ha, I don’t have a discovery for the moment.

chemelli74 commented 2 years ago

Missed the part on asking me to update, i am on: core-2021.12.10 supervisor-2022.01.1 not comfortable at the moment upgrading to beta

@djansen1987, there is not a official release to update to.

Simone

chemelli74 commented 2 years ago

Seems the token is not saved here for some reason. So can you confirm that TV is working right after adding it to HA, but at next reboot you get again a discovery? Simone

I can change volume with ha on the TV. So tv work fine with ha. Maybe it’s because it’s an old model ? (2015). But if if reboot ha, I don’t have a discovery for the moment.

Your diagnostics says it's using the new websocket method:

        "method": "websocket",
        "model": "UE65KU6680",
        "name": "Samsung",
        "port": 8002

which is token based.

Simone

djansen1987 commented 2 years ago

Still have the issue

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.2.2",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.9.7",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Amsterdam",
    "os_name": "Linux",
    "os_version": "5.10.91",
    "supervisor": "2022.01.1",
    "host_os": "Home Assistant OS 7.2",
    "docker_version": "20.10.9",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "saj_esolar": {
      "version": "1.2.9",
      "requirements": []
    },
    "toon_climate": {
      "version": "1.0.12",
      "requirements": []
    },
    "afvalbeheer": {
      "version": "4.9.2",
      "requirements": [
        "rsa",
        "pycryptodome"
      ]
    },
    "toon_boilerstatus": {
      "version": "1.0.11",
      "requirements": []
    },
    "custom_component_analytics": {
      "version": "0.0.1",
      "requirements": []
    },
    "nodered": {
      "version": "1.0.6",
      "requirements": []
    },
    "philips_airpurifier": {
      "version": "0.4.0",
      "requirements": [
        "aioairctrl @ git+https://github.com/betaboon/aioairctrl@v0.2.1"
      ]
    },
    "philips_airpurifier_coap": {
      "version": "0.7.0",
      "requirements": [
        "aioairctrl @ git+https://github.com/betaboon/aioairctrl@v0.2.1"
      ]
    },
    "hacs": {
      "version": "1.21.0",
      "requirements": [
        "aiogithubapi>=21.11.0"
      ]
    },
    "toon_smartmeter": {
      "version": "1.0.18",
      "requirements": []
    }
  },
  "integration_manifest": {
    "domain": "samsungtv",
    "name": "Samsung Smart TV",
    "documentation": "https://www.home-assistant.io/integrations/samsungtv",
    "requirements": [
      "getmac==0.8.2",
      "samsungctl[websocket]==0.7.1",
      "samsungtvws==1.6.0",
      "wakeonlan==2.0.1"
    ],
    "ssdp": [
      {
        "st": "urn:samsung.com:device:RemoteControlReceiver:1"
      }
    ],
    "zeroconf": [
      {
        "type": "_airplay._tcp.local.",
        "properties": {
          "manufacturer": "samsung*"
        }
      }
    ],
    "dhcp": [
      {
        "hostname": "tizen*"
      },
      {
        "macaddress": "8CC8CD*"
      },
      {
        "macaddress": "606BBD*"
      },
      {
        "macaddress": "F47B5E*"
      },
      {
        "macaddress": "4844F7*"
      }
    ],
    "codeowners": [
      "@escoand",
      "@chemelli74"
    ],
    "config_flow": true,
    "iot_class": "local_polling",
    "is_built_in": true
  },
  "data": {
    "entry": {
      "entry_id": "xxxxxx",
      "version": 2,
      "domain": "samsungtv",
      "title": "samsungwktv (QE65Q80TALXXN)",
      "data": {
        "host": "192.168.xx.xx",
        "mac": "70:b1:3d:xx:xx:xx",
        "manufacturer": "Samsung",
        "method": "websocket",
        "model": "QE65Q80TALXXN",
        "name": "samsungwktv",
        "port": 8002,
        "token": "**REDACTED**"
      },
      "options": {},
      "pref_disable_new_entities": false,
      "pref_disable_polling": false,
      "source": "user",
      "unique_id": "xxxx",
      "disabled_by": null
    }
  }
}
epenet commented 2 years ago

Can you please check if the new patch release 2022.2.8 has improved the situation?

landaisbenj commented 2 years ago

Hello. This morning I have this

54D5101C-81DB-4D28-8845-B1FC24F27CC0

landaisbenj commented 2 years ago

After reconfiguration and 1 restart, i have this : config_entry-samsungtv-d60f4b349f3570c2a46676978086bd5a.json.txt

chemelli74 commented 2 years ago

After reconfiguration and 1 restart, i have this : config_entry-samsungtv-d60f4b349f3570c2a46676978086bd5a.json.txt

And it still asks for reconfiguration ?

landaisbenj commented 2 years ago

Not for the moment😊

chemelli74 commented 2 years ago

I think this is now solved and can be closed.

Simone

landaisbenj commented 2 years ago

Yes I close. Thanks.

djansen1987 commented 2 years ago

Dear, i see the item is closed but i still get a message on my tv as post before when i turn on the TV. Before i was getting it continuedly until declining. Now i only get it once every power on of the tv.

Don't see the reconnect warning anymore in HA.

I am on: core-2022.2.9 supervisor-2022.01.1

epenet commented 2 years ago

I recently discovered that I have a choice between "Off" / "First Time Only" / "Always On" in my Samsung Device Connection Manager I assume it is set to Alway On, please ensure that you set it to First Time Only

djansen1987 commented 2 years ago

I don't see that option on my tv.

Today i removed the integration in HA and removed all allowed devices on the tv to make a fresh start. Restarted HA, it then discovered the TV again and added the integration and allowed on the TV.

Then i Turned off the TV, wait 2-5 minutes, turned the TV back on and i then had to Grand Homeassistant access to the tv. I could reproduce this with every power off/on of the TV

Integration Diagnostic:

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.2.9",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.9.7",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Amsterdam",
    "os_name": "Linux",
    "os_version": "5.10.98",
    "supervisor": "2022.01.1",
    "host_os": "Home Assistant OS 7.4",
    "docker_version": "20.10.9",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "saj_esolar": {
      "version": "1.2.9",
      "requirements": []
    },
    "toon_climate": {
      "version": "1.0.12",
      "requirements": []
    },
    "afvalbeheer": {
      "version": "4.9.2",
      "requirements": [
        "rsa",
        "pycryptodome"
      ]
    },
    "toon_boilerstatus": {
      "version": "1.0.11",
      "requirements": []
    },
    "custom_component_analytics": {
      "version": "0.0.1",
      "requirements": []
    },
    "nodered": {
      "version": "1.0.6",
      "requirements": []
    },
    "philips_airpurifier": {
      "version": "0.4.0",
      "requirements": [
        "aioairctrl @ git+https://github.com/betaboon/aioairctrl@v0.2.1"
      ]
    },
    "philips_airpurifier_coap": {
      "version": "0.7.0",
      "requirements": [
        "aioairctrl @ git+https://github.com/betaboon/aioairctrl@v0.2.1"
      ]
    },
    "hacs": {
      "version": "1.23.0",
      "requirements": [
        "aiogithubapi>=21.11.0"
      ]
    },
    "toon_smartmeter": {
      "version": "1.0.18",
      "requirements": []
    }
  },
  "integration_manifest": {
    "domain": "samsungtv",
    "name": "Samsung Smart TV",
    "documentation": "https://www.home-assistant.io/integrations/samsungtv",
    "requirements": [
      "getmac==0.8.2",
      "samsungctl[websocket]==0.7.1",
      "samsungtvws==1.6.0",
      "wakeonlan==2.0.1"
    ],
    "ssdp": [
      {
        "st": "urn:samsung.com:device:RemoteControlReceiver:1"
      }
    ],
    "zeroconf": [
      {
        "type": "_airplay._tcp.local.",
        "properties": {
          "manufacturer": "samsung*"
        }
      }
    ],
    "dhcp": [
      {
        "hostname": "tizen*"
      },
      {
        "macaddress": "8CC8CD*"
      },
      {
        "macaddress": "606BBD*"
      },
      {
        "macaddress": "F47B5E*"
      },
      {
        "macaddress": "4844F7*"
      }
    ],
    "codeowners": [
      "@escoand",
      "@chemelli74"
    ],
    "config_flow": true,
    "iot_class": "local_polling",
    "is_built_in": true
  },
  "data": {
    "entry": {
      "entry_id": "xxxxxxxxxxxxxxx",
      "version": 2,
      "domain": "samsungtv",
      "title": "samsungwktv (QE65Q80TALXXN)",
      "data": {
        "host": "192.168.xx.xx",
        "mac": "70:b1:xx:xx:xx:xx",
        "manufacturer": "Samsung",
        "method": "websocket",
        "model": "QE65Q80TALXXN",
        "name": "samsungwktv",
        "port": 8002,
        "token": "**REDACTED**"
      },
      "options": {},
      "pref_disable_new_entities": false,
      "pref_disable_polling": false,
      "source": "zeroconf",
      "unique_id": "xxxxxxxxxxxxx",
      "disabled_by": null
    }
  }
}
landaisbenj commented 2 years ago

Hello, after last update of core, i have this : image Before make a re configuration, i would know if i need to get log ?

menloperk commented 2 years ago

This integration hasn't been working properly since I migrated to HA. I love HA but this integration component is just lame. Everytime I need to reconfigure the configuration which doesn't make sense. Upgraded to latest HA version and now it discovers yet another Samsung TV although it is just exactly the same TV!?!?! Can we fix this one or I will delete it.

menloperk commented 2 years ago

This is what I mean: image

bdraco commented 2 years ago

Im pretty sure the UDN is changing. We should probably check the mac address as well now that we have it

epenet commented 2 years ago

I too was hit by the triple-integration issue (one marked as OK, one marked as Discovered and one marked as Attention Required)

I think that "Attention required" may be due to a ConnectionFailure that is raised by the upstream library. When opening a connection, the upstream library is expecting the first event to be of type "ms.channel.connect", but sometimes it looks like the first event is instead some kind of keep-alive event of type "ed.edenTV.update", and this triggers the connection failed routine.

2022-03-05 19:41:48 DEBUG (MainThread) [samsungtvws.async_connection] WS url wss://192.168.0.14:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=00000000
2022-03-05 19:41:50 DEBUG (MainThread) [samsungtvws.helper] Processing API response: {"data":{"update_type":"ed.edenApp.update"},"event":"ed.edenTV.update"}
2022-03-05 19:41:50 DEBUG (MainThread) [samsungtvws.async_connection] Connection closed.
2022-03-05 19:41:50 DEBUG (MainThread) [custom_components.samsungtv] ConnectionFailure ConnectionFailure({'data': {'update_type': 'ed.edenApp.update'}, 'event': 'ed.edenTV.update'})
2022-03-05 19:41:50 DEBUG (MainThread) [custom_components.samsungtv] Access denied in getting remote object
epenet commented 2 years ago

Upstream PR opened: https://github.com/xchwarze/samsung-tv-ws-api/pull/71

epenet commented 2 years ago

Im pretty sure the UDN is changing. We should probably check the mac address as well now that we have it

@bdraco I compared the UDN in discovery logs to the unique_id in the storage (core.config_entries) and they are identical. I am not convinced that is the root cause. I started looking at the mac address and I have discovered an issue loading it from the device_info. Maybe it won't help for this issue, but I created PR #67804

epenet commented 2 years ago

@bdraco I have investigated the UDN issue some more, and I have discovered that (at least on my television) the udn returned by the REST-API (user/dhcp/zeroconf flows) is not the same as the udn returned by the SSDP discovery.

I think maybe SSDP should be adjusted to use the UDN from the REST-API?

epenet commented 2 years ago

Separate PR created for the UDN mismatch: #67811

epenet commented 2 years ago

The dev branch has been updated again today. Can you please test again?

image

landaisbenj commented 2 years ago

I just do your stuf, and don't remove official integration. In log, i have this, but no longueur have 3 integrations.

2022-03-08 13:50:32 DEBUG (MainThread) [custom_components.samsungtv] Checking if TV 192.168.0.15 is on using websocket
2022-03-08 13:50:32 DEBUG (MainThread) [custom_components.samsungtv] Create SamsungTVWSBridge for 192.168.0.15
2022-03-08 13:50:32 DEBUG (MainThread) [samsungtvws.async_connection] WS url wss://192.168.0.15:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=None
2022-03-08 13:50:37 DEBUG (MainThread) [custom_components.samsungtv] Failed to get remote for 192.168.0.15: TimeoutError()

image

And now, samsung entity work again : image

epenet commented 2 years ago

If the TV is offline, then this is correct behaviour (TimeoutError after 5 seconds)

landaisbenj commented 2 years ago

yes TV is offline, i'm on work.