Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slow response with Version: 1.2.3 #22

Open
avico78 opened this issue Oct 1, 2022 · 15 comments
Open

slow response with Version: 1.2.3 #22

avico78 opened this issue Oct 1, 2022 · 15 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@avico78
Copy link

avico78 commented Oct 1, 2022

After 2 years with v1.1 I try to upgrade to latest ,
I also update AD to latest .

1.It is much slower (click on telegram --> getting result takes more than 20 sec)
i.e - when i click on "state person " - i see in the log it fetching from HA hundreds of entities not related to person .
very small example from debug:


2022-10-01 11:41:14.768606 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_114
2022-10-01 11:41:14.787023 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_115
2022-10-01 11:41:14.819108 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_115
2022-10-01 11:41:14.845368 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_116
2022-10-01 11:41:14.857502 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_116
2022-10-01 11:41:14.866491 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_117
2022-10-01 11:41:14.886148 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_117
2022-10-01 11:41:14.925392 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_118
2022-10-01 11:41:14.947845 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_118
2022-10-01 11:41:14.960707 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_119
2022-10-01 11:41:14.976491 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_119
2022-10-01 11:41:15.039052 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_120
2022-10-01 11:41:15.075520 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_120
2022-10-01 11:41:15.091380 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_121
2022-10-01 11:41:15.105078 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_121
2022-10-01 11:41:15.139891 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_122
2022-10-01 11:41:15.201828 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_122
2022-10-01 11:41:15.257305 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_123
2022-10-01 11:41:15.268834 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_123
2022-10-01 11:41:15.290334 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_124
2022-10-01 11:41:15.300345 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_124
2022-10-01 11:41:15.335800 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_125
2022-10-01 11:41:15.361040 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: adding: persistent_notification.notification_125
2022-10-01 11:41:15.400425 INFO TelegramBot: DEBUG: TelegramBot: _get_state_filtered: persistent_notification.notification_126

This not happened with v1.1

i suspect it related with how filtering list working in new version but not sure as i use exactly same configuration in the app.yaml

Actually when click on "get log" or "get error log" it hangs for ~1 min

2.How does the Waze location works?
It doesn't appear in menu and Person location doesn't return with any calculation of routing .

  1. from time to time i see error in the error.log
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.1.168.113', port=8123): Max retries exceeded with url: /api/error_log (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7aca47bf10>: Failed to establish a new connection: [Errno 110] Operation timed out'))

I see in v1.2.3 there's need to add a token to apps.yaml- where exactly it's needed?
I added the token and ha_url - but keep getting this errors .
I enter to the AD docker and manage to
execute curl - so not sure where this error coming:

from inside the AD docker:

/usr/src/app
curl -X GET -H "Authorization: Bearer MyLongLiveTokenString \
        -H "Content-Type: application/json" \
        http://homeassistant:8123/api/error_log

# getting result successfully 

2022-10-01 11:52:49.706 INFO (MainThread) [homeassistant.components.automation.dahua_vto_all_events] Dahua VTO All Events: Running automation actions
2022-10-01 11:52:49.709 INFO (MainThread) [homeassistant.components.automation.dahua_vto_all_events] Dahua VTO All Events: Executing step call service
2022-10-01 11:52:50.729 INFO (SyncWorker_3) [homeassistant.components.linksys_smart.device_tracker] Checking Linksys Smart Wifi

apps.yaml

TelegramBot:
  module:                   TelegramBot
  class:                    TelegramBot
  debug:                    True
  extend_system:            "binary_sensor.updater"
  filter_blacklist:    
   - "light.dcede305_a5afe582"
   - "light.9c9aec1d_a4871501"
   - "light.45690a88_c9b8dc22"
   - "light.c7f7c676_a53ca2bd" 
   - persistent_notification 

  routing:
    waze:
      region:               IL
      avoid_toll_roads:     True

  hass:
    token: 'sOmeToKeN'
    ha_url: http://192.1.168.113:8123  
@foxcris
Copy link
Owner

foxcris commented Oct 3, 2022

hi,

regarding your questions:

  1. It is much slower (click on telegram --> getting result takes more than 20 sec)
    That seems not normal. I do not have such delay between the choosen action an the result. How big is your home-assistant installation?

The "_get_state_filtered" function implements the whitelist and blacklist on all entites in home-assistant. If you perform an initial request with telegram bot such as "state person" all entites from home-assistant are requested and filtered. You can disable the debug output by changing the "debug" option to "false". So if the output is slowing down your system that should be gone then.

The way you configured "filter_blacklist" all entities with e.g. "light.dcede305_a5afe582" in theire entitiy name are removed an not handled by the telegrambot.

I will think about a way to only request the related entities regarding the action you chose. But probably there wasn't a good way to do this with appdaemon. Do you have such massive enitites in you home-assitant instance?

  1. How does the Waze location works?
    I just looked at the code. You should send a location to the telegrambot. The bot should then calculate your way to each configured zone in home-assistant.

  2. from time to time i see error in the error.log
    Is this error related to any action with telegrambot? Telegrambot is only using the "/api/error_log" when you use the action "get_log". With it a simple request is made to the home-assistant api to get the logentries. The last 50 entries are then send to the telegram channel. Please take care that you configured the configuration options for the hass "token" and "ha_url" correctly.

  3. I see in v1.2.3 there's need to add a token to apps.yaml- where exactly it's needed?
    I added the token and ha_url - but keep getting this errors .
    I enter to the AD docker and manage to execute curl - so not sure where this error coming.

The hass "token" an "ha_url" are used the the actions "get log" and "get error log". When you can use curl to run a request from appdaemon against home-assistant using the configured "ha_url" thats good. The token is needed to authenticate against home-assistant. You can check it by manually sending the following headers with curl "Authorization": "Bearer {token}", "Content-Type": "application/json".

curl -X GET -H "Authorization: Bearer ABCDEFGH" -H "Content-Type: application/json" http://localhost:8123/api/error_log

@foxcris
Copy link
Owner

foxcris commented Oct 3, 2022

The waze feature is not working currently on my side. I get an error, have to look into it.

@GeitjeG
Copy link
Contributor

GeitjeG commented Oct 3, 2022

This delay sounds familiar. For me if I press for example "turnon light" in Telegram, there is also a delay of about 20 seconds. In my case this has always been the case. I think it depends on the number of devices/entities you have, or the size of DB? Since I cleaned up lots of my unused devices, the result is 2 times quicker (delay was 50-60 seconds before). Apart from that for me this is not a big issue as I pin the results of the frequent used commands to my Telegram app. This way I can acces them quick. As long as the HA instance is not restarted, the device numbered codes remain working, without issueing a new "turnon light" command.

The Waze function I do not use, also the use-case of this function is not clear to me.

@avico78 : Did you also update appdaemon to newest version? I am reluctant to update because it might break this telegrambot?

@foxcris
Copy link
Owner

foxcris commented Oct 3, 2022

If you also have this delay it probably has to do with the number of entities in home-assistant. How many are in your instance?

I am currently running "acockburn/appdaemon:latest" without any issues for me.

@foxcris foxcris self-assigned this Oct 3, 2022
@foxcris foxcris added bug Something isn't working help wanted Extra attention is needed labels Oct 3, 2022
@avico78
Copy link
Author

avico78 commented Oct 3, 2022

@GeitjeG
AD version 1.29.2
there are 323 entities

on v1.1 - with same number of entities the respond is fast ,
on the other hand - on v1.2.3 it takes ~20 second to get persons .
seems the reason for this slow response coming from the _get_state_filtered

def _get_state_filtered(self):
....
  self._log_debug(f'adding: {entity}')

Suggestion :
Maybe it would be faster fetching only the relevant entities and not all the entities?
meaning - when click on person why it's required to fetch lights?

for person :
when click on person , i'm getting the map and coordination for single entities ,
in log:

2022-10-03 16:49:26.061647 WARNING HASS: Error calling Home Assistant service default/telegram_bot/send_location
2022-10-03 16:49:26.062533 WARNING HASS: Code: 400, error: 400: Bad Request
2022-10-03 16:49:26.071888 INFO TelegramBot: DEBUG: TelegramBot: _getid: idlist: friendly_name
2022-10-03 16:49:26.078878 WARNING HASS: Error calling Home Assistant service default/telegram_bot/send_location
2022-10-03 16:49:26.079838 WARNING HASS: Code: 400, error: 400: Bad Request
2022-10-03 16:49:26.082120 INFO TelegramBot: DEBUG: TelegramBot: _cmd_state_person: msg person: avi
state: home
latitude: 31.93234617
longitude: 31.09023482
gps_accuracy: 16

for logs:

When clicking on get log or get error log - nothing happened for ~2-3 min,
looks it hangs (can't recall the /help or push any button).
after a while i see the activity on appdaemon.log:

2022-10-03 17:08:36.433512 WARNING AppDaemon: Logged an error to /conf/logs/error.log
2022-10-03 17:08:36.436509 WARNING AppDaemon: callback _receive_telegram_callback() in TelegramBot has now completed

in same time an error show in error.log

2022-10-03 17:08:36.430262 WARNING TelegramBot: ------------------------------------------------------------
2022-10-03 17:08:36.432174 WARNING TelegramBot: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/lib/python3.9/http/client.py", line 1285, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.9/http/client.py", line 1331, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.9/http/client.py", line 1280, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.9/http/client.py", line 1040, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.9/http/client.py", line 980, in send
    self.connect()
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 205, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f73c6d4a460>: Failed to establish a new connection: [Errno 110] Operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.1.168.113', port=8123): Max retries exceeded with url: /api/error_log (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f73c6d4a460>: Failed to establish a new connection: [Errno 110] Operation timed out'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/appdaemon/threading.py", line 950, in worker
    funcref(args["event"], data, self.AD.events.sanitize_event_kwargs(app, args["kwargs"]))
  File "/conf/apps/TelegramBot.py", line 529, in _receive_telegram_callback
    method(target_id=callback_id)
  File "/conf/apps/TelegramBot.py", line 954, in _cmd_get_log
    res=requests.get(f"{ha_url}/api/error_log", headers=custom_headers)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.1.168.113', port=8123): Max retries exceeded with url: /api/error_log (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f73c6d4a460>: Failed to establish a new connection: [Errno 110] Operation timed out'))


@GeitjeG
Copy link
Contributor

GeitjeG commented Oct 6, 2022

I have 1142 entities, I might want to clean up a little :-)
However it does not seem to be the cause of lag if I see your story.

@avico78
Copy link
Author

avico78 commented Oct 6, 2022

@GeitjeG - thanks , i can live with the lag (i just suppress the print for the entities ) ,
the thing that bother me is the get log or get error log (I add the details/log in previous post),
second , the waze - not working.

@foxcris
Copy link
Owner

foxcris commented Oct 9, 2022

To reduce the delay. What do you think about the following solution:

  1. periodically request the complete enity list from home-assistant, e.g. every hour
  2. on triggered telegrambot action only the state of the pertaining entities is refreshed

@foxcris
Copy link
Owner

foxcris commented Oct 9, 2022

Regarding the retrievement of the log.
There are currently two actions available:

  • get_log
  • get_error_log

Both are using different api endpoints.
get_log -> https://home-assistant.lan/api/error_log
get_error_log -> https://home-assistant.lan/api/error/all

Currently only get_log is working as the endpoint "api/error/all" is not available anymore. (https://developers.home-assistant.io/docs/api/rest). I suggest we just remove the action"get_error_log".

@foxcris
Copy link
Owner

foxcris commented Oct 9, 2022

With waze correct workflow was:

  1. Send a location to the telegrambot.
  2. The telegrambot extracts the gps coordiantes from the location. For each defined zone in home-assistant it calculates the required timed to get there from the posted location.

Problem:
If you send a location message to the telegrambot home-assistant only creates an empty text event.

Thus if this functionality is still required we have to find a differend workflow. Does one of you need this functionality? Any ideas?

@foxcris
Copy link
Owner

foxcris commented Oct 9, 2022

@avico78: Just realised, that you had problems with the get_log function. According to your error message in the log you have som connection problems between appdaemon an home-assistant. Are they both on the same docker network? Are you using a reverse proxy in front of home-assistant?

@avico78
Copy link
Author

avico78 commented Oct 11, 2022

@avico78: Just realised, that you had problems with the get_log function. According to your error message in the log you have som connection problems between appdaemon an home-assistant. Are they both on the same docker network? Are you using a reverse proxy in front of home-assistant?

from AP i'm able to get data from HA:

curl -X GET -H "Authorization: Bearer asd.eyJpc3MiOiI4ODJlOTk1MzliMmM0NWM1OWY1NTg4ZWJlMGMxMjZlMSIsImlhdCI6MTU4NzE0OTIwNiwiZXhwIjoxOTAyNTA5MjA2fQ.asd" -H "Content-Type: application/json" http://192.168.1.113:8123/api/error_log

When click on get_error_log on telegram - it hands for ~3 min and than i see in error.log:

2022-10-11 21:27:40.764356 WARNING TelegramBot: Unexpected error in worker for App TelegramBot:
2022-10-11 21:27:40.765608 WARNING TelegramBot: Worker Ags: {'id': '917d1db2d9244197b006ba905522bad8', 'name': 'TelegramBot', 'objectid': '4d3858fd141b4300a2f6017639677f81', 'type': 'event', 'event': 'telegram_callback', 'function': <bound method TelegramBot._receive_telegram_callback of <TelegramBot.TelegramBot object at 0x7f4d71102e80>>, 'data': {'id': '3103717630843968301', 'chat_instance': '-3181509289854929877', 'data': '/get_error_log', 'message': {'message_id': 69367, 'date': 1665512711, 'chat': {'id': 722640573, 'type': 'private', 'first_name': 'xxxx'}, 'text': 'help: Help\nstate cover: State of cover\nstate vacuum: State of vacuum\nstate light: State of light\nstate climate: State of climate\nstate person: State of person\nopen cover: Open cover\nclose cover: Close cover\nturnoff light: Turn off light\nturnon light: Turn on light\nstart vacuum: Start vacuum\nstop vacuum: Stop running vacuum\nrestart hass: Restart hass\nstate system: State of home-assistant\nstate sensor: State of sensors\nget version: Get version of telegrambot\nexecute script: Execute script\nturnon automation: Turn on automation\nturnoff automation: Turn off automation\ntrigger automation: Trigger automation\nstate automation: State of automation\nget log: Get last lines of the home-assistant log\nget error log: Get home-assistant error log', 'entities': [], 'caption_entities': [], 'photo': [], 'new_chat_members': [], 'new_chat_photo': [], 'delete_chat_photo': False, 'group_chat_created': False, 'supergroup_chat_created': False, 'channel_chat_created': False, 'reply_markup': {'inline_keyboard': [[{'text': 'help', 'callback_data': '/help'}], [{'text': 'state cover', 'callback_data': '/state_cover'}, {'text': 'state vacuum', 'callback_data': '/state_vacuum'}], [{'text': 'state light', 'callback_data': '/state_light'}, {'text': 'state climate', 'callback_data': '/state_climate'}], [{'text': 'state person', 'callback_data': '/state_person'}, {'text': 'open cover', 'callback_data': '/open_cover'}], [{'text': 'close cover', 'callback_data': '/close_cover'}, {'text': 'turnoff light', 'callback_data': '/turnoff_light'}], [{'text': 'turnon light', 'callback_data': '/turnon_light'}, {'text': 'start vacuum', 'callback_data': '/start_vacuum'}], [{'text': 'stop vacuum', 'callback_data': '/stop_vacuum'}, {'text': 'restart hass', 'callback_data': '/restart_hass'}], [{'text': 'state system', 'callback_data': '/state_system'}, {'text': 'state sensor', 'callback_data': '/state_sensor'}], [{'text': 'get version', 'callback_data': '/get_version'}, {'text': 'execute script', 'callback_data': '/execute_script'}], [{'text': 'turnon automation', 'callback_data': '/turnon_automation'}, {'text': 'turnoff automation', 'callback_data': '/turnoff_automation'}], [{'text': 'trigger automation', 'callback_data': '/trigger_automation'}, {'text': 'state automation', 'callback_data': '/state_automation'}], [{'text': 'get log', 'callback_data': '/get_log'}, {'text': 'get error log', 'callback_data': '/get_error_log'}]]}, 'from': {'id': 868968144, 'first_name': 'HomeAssistant', 'is_bot': True, 'username': 'xxxxxco99_bot'}}, 'chat_id': 722640573, 'user_id': 722640573, 'from_first': 'xxxxx', 'from_last': None, 'command': '/get_error_log', 'args': [], 'metadata': {'origin': 'LOCAL', 'time_fired': '2022-10-11T18:25:28.585159+00:00', 'context': {'id': '01GF44PT0906CKAAC9EAT1A89C', 'parent_id': None, 'user_id': None}}}, 'pin_app': True, 'pin_thread': 1, 'kwargs': {'__thread_id': 'thread-1'}}
2022-10-11 21:27:40.766816 WARNING TelegramBot: ------------------------------------------------------------
2022-10-11 21:27:40.879722 WARNING TelegramBot: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/lib/python3.9/http/client.py", line 1285, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.9/http/client.py", line 1331, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.9/http/client.py", line 1280, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.9/http/client.py", line 1040, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.9/http/client.py", line 980, in send
    self.connect()
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 205, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f4d6facb5b0>: Failed to establish a new connection: [Errno 110] Operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 995, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.1.168.113', port=8123): Max retries exceeded with url: /api/error/all (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4d6facb5b0>: Failed to establish a new connection: [Errno 110] Operation timed out'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/appdaemon/threading.py", line 950, in worker
    funcref(args["event"], data, self.AD.events.sanitize_event_kwargs(app, args["kwargs"]))
  File "/conf/apps/TelegramBot.py", line 529, in _receive_telegram_callback
    method(target_id=callback_id)
  File "/conf/apps/TelegramBot.py", line 988, in _cmd_get_error_log
    res=requests.get(f"{ha_url}/api/error/all", headers=custom_headers)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.1.168.113', port=8123): Max retries exceeded with url: /api/error/all (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4d6facb5b0>: Failed to establish a new connection: [Errno 110] Operation timed out'))

And yes , using traefik as RP ,
In HA configuration.yaml I add the trusted_network range(AD ip is 172.29.0.2) :

  auth_providers:
    - type: homeassistant
    - type: trusted_networks
      trusted_networks:
        - 192.168.1.0/24
        - 172.29.0.0/20

@foxcris
Copy link
Owner

foxcris commented Oct 13, 2022

@avico78: With curl you used the ip 192.168.1.113. The appdaemon error log shows the ip 192.1.168.113. Is this just a typo in your post or a wrong configuration of appdaemon?

@avico78
Copy link
Author

avico78 commented Oct 13, 2022

@foxcris - nice catch !
fool me i missed it:)

it did solved the get_log but get_errors still not working ,
btw - found another issue in _homeassistant_update_available
which send an update for new version ,
the reason is the binary_sensor.updater is deprecated .
i managed to solved it by :

self.listen_state(
            self._homeassistant_update_available,
            "binary_sensor.home_assistant_website_update_available", duration=1)

and

    def _homeassistant_update_available(self, entity,  attribute, old, new, duration):
        if new == "on":
            newest_version = self.get_state('sensor.home_assistant_website')
            release_notes = self.get_state('sensor.home_assistant_website', attribute="release_notes")
            msg = f"Home-assistant update available! Newest version: {newest_version}.\n Release Notes: {release_notes}"
            self._log_info(msg)
            self.call_service(
                'telegram_bot/send_message',
                message=self._escape_markdown(msg))

Test:
image

Questions if I may:

1.Is it possible to send text to the bot which can be use in some HA automation ?
2.Is it possible to get alert to bot for failed logging attempt ,
i.e wrong password, ip not in trusted_proxies

@foxcris
Copy link
Owner

foxcris commented Oct 14, 2022

  1. If you send text to the bot i can catch it. But how do we want to configure what to do with the text? Till now all the commands give every reply an context.

  2. I searched the home-assistant.io documentation but couldn't find any event for an login attempt. Thus i think that's currently not possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants