gcobb321 / icloud3

iCloud3 v3 - iCloud3 is an advanced iDevice tracker that uses Apple iCloud account and HA Companion App data for presence detection and location based automations.
MIT License
566 stars 55 forks source link

icloud3 2.2 RC11b not starting #64

Closed bobvmierlo closed 4 years ago

bobvmierlo commented 4 years ago

Just tried to migrate to v2.2 with RC11b from v2.1 by following the installation steps and creating a icloud3_dev folder. Change my configuration.yaml file accordingly but it's not starting the integration at all. See errors from HA logs below.

Errors:

Log Details (ERROR)
Logger: custom_components.icloud3_dev.device_tracker
Source: custom_components/icloud3_dev/device_tracker.py:1165
Integration: icloud3_dev
First occurred: 10:37:03 PM (1 occurrences)
Last logged: 10:37:03 PM

'notify'
Traceback (most recent call last):
  File "/config/custom_components/icloud3_dev/device_tracker.py", line 1165, in _start_icloud3
    notify_services = dict(services.__dict__)['_services']['notify']
KeyError: 'notify'
Logger: frontend.js.latest.202008110
Source: components/system_log/__init__.py:193
First occurred: 10:39:22 PM (6 occurrences)
Last logged: 10:40:36 PM

https://MYURL/local/custom_cards/icloud3-event-log-card.js?v=2.2:1381:75 Uncaught TypeError: Cannot read property 'attributes' of undefined
https://MYURL/local/custom_cards/icloud3-event-log-card.js?v=2.2:1352:71 Uncaught TypeError: Cannot read property 'attributes' of undefined
https://MYURL/local/custom_cards/icloud3-event-log-card.js?v=2.2:1274:71 Uncaught TypeError: Cannot read property 'attributes' of undefined
https://MYURL/lovelace/default_view:0:0 Uncaught

My config_ic3.yaml

###########################################################
#
#   iCloud3 Configuration Parameters
#
#   These parameters will override those specified in the HA
#   configuration.yaml file. They can be used to change the
#   iCloud3 operations without restarting HA. To do this,
#   change the parameter in this file and select 'Restart-iC3'
#   on the iCloud3 Event Log screen.
#
###########################################################
log_level: eventlog, debug
#log_level: debug+rawdata

#--Tracking Parameters-------------------------------------
track_devices:
  - iphone_1 > EMAIL , iPhone1
  - iphone_2 > EMAIL, iPhone2

#--Zone Parameters-----------------------------------------
#inzone_interval: '1 hr'
#center_in_zone: True
#stationary_inzone_interval: '20 min'
#stationary_still_time: '10 min'

#--Accuracy Parameters-------------------------------------
#gps_accuracy_threshold: 100
#ignore_gps_accuracy_inzone: True
old_location_threshold: '2 min'

#--Waze Parameters-----------------------------------------
#distance_method: calc
waze_region: EU
#waze_min_distance: 1
#waze_max_distance: 9999
#waze_realtime: False

#-- Other Parameters---------------------------------------
#travel_time_factor: .6
unit_of_measurement: km
exclude_sensors: zon2,zon3,zonts,lon2,lzon3,lzon4,bat,batstat,cnt,gpsac,alt,vacc

My configuration.yaml entry:

  - platform: icloud3_dev
    username: !secret icloud_username
    password: !secret icloud3_pw
    tracking_method: fmf
    config_ic3_file_name: /config/config_ic3.yaml
gcobb321 commented 4 years ago

The ‘notify’ error is happening when iCloud3 it’s extracting the devices that can receive messages from the list of HA services and there are none. I’ll add some error checking to catch the error. That error is probably leading to the other error.

  1. On your phone, open the iOS app. Go to HASidebar > About.
  2. What version of the iOS app are you running?
  3. Go to General. Do you have a Device Name field? What is it?
  4. On your HA computer, Go to HASidebar > Developer Tool’s > Services and list the entities. Scroll down to the ‘notify.mobile_app_phonename’ area and see if any are listed. What are they? It should list one for each phone.

———————— Gary Cobb On Aug 19, 2020, 4:48 PM -0400, bobvmierlo notifications@github.com, wrote:

Just tried to migrate to v2.2 with RC11b from v2.1 by following the installation steps and creating a icloud3_dev folder. Change my configuration.yaml file accordingly but it's not starting the integration at all. See errors from HA logs below. Errors: Log Details (ERROR) Logger: custom_components.icloud3_dev.device_tracker Source: custom_components/icloud3_dev/device_tracker.py:1165 Integration: icloud3_dev First occurred: 10:37:03 PM (1 occurrences) Last logged: 10:37:03 PM

'notify' Traceback (most recent call last): File "/config/custom_components/icloud3_dev/device_tracker.py", line 1165, in _start_icloud3 notify_services = dict(services.dict)['_services']['notify'] KeyError: 'notify' Logger: frontend.js.latest.202008110 Source: components/system_log/init.py:193 First occurred: 10:39:22 PM (6 occurrences) Last logged: 10:40:36 PM

https://MYURL/local/custom_cards/icloud3-event-log-card.js?v=2.2:1381:75 Uncaught TypeError: Cannot read property 'attributes' of undefined https://MYURL/local/custom_cards/icloud3-event-log-card.js?v=2.2:1352:71 Uncaught TypeError: Cannot read property 'attributes' of undefined https://MYURL/local/custom_cards/icloud3-event-log-card.js?v=2.2:1274:71 Uncaught TypeError: Cannot read property 'attributes' of undefined https://MYURL/lovelace/default_view:0:0 Uncaught My config_ic3.yaml ########################################################### #

iCloud3 Configuration Parameters

#

These parameters will override those specified in the HA

configuration.yaml file. They can be used to change the

iCloud3 operations without restarting HA. To do this,

change the parameter in this file and select 'Restart-iC3'

on the iCloud3 Event Log screen.

# ########################################################### log_level: eventlog, debug

log_level: debug+rawdata

--Tracking Parameters-------------------------------------

track_devices:

  • iphone_1 > EMAIL , iPhone1
  • iphone_2 > EMAIL, iPhone2

--Zone Parameters-----------------------------------------

inzone_interval: '1 hr'

center_in_zone: True

stationary_inzone_interval: '20 min'

stationary_still_time: '10 min'

--Accuracy Parameters-------------------------------------

gps_accuracy_threshold: 100

ignore_gps_accuracy_inzone: True

old_location_threshold: '2 min'

--Waze Parameters-----------------------------------------

distance_method: calc

waze_region: EU

waze_min_distance: 1

waze_max_distance: 9999

waze_realtime: False

-- Other Parameters---------------------------------------

travel_time_factor: .6

unit_of_measurement: km exclude_sensors: zon2,zon3,zonts,lon2,lzon3,lzon4,bat,batstat,cnt,gpsac,alt,vacc My configuration.yaml entry:

  • platform: icloud3_dev username: !secret icloud_username password: !secret icloud3_pw tracking_method: fmf config_ic3_file_name: /config/config_ic3.yaml — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
bobvmierlo commented 4 years ago

I'm using 2020.5.2 (1), devicename is "iPhone 11 van Bob" which is identical to the devicename in the general iOS settings. In the services I have the 2 notify services corresponding with the 2 iPhones in our household, although I think these services are related to the "old" v2.1 integration.

bobvmierlo commented 4 years ago

The event log card keeps showing this screen: image

gcobb321 commented 4 years ago

Actually, the notify name has nothing to do with iCloud3, the iOS app controls it. All iCloud3 wants to do is get it to send a request_location_update. The red iCloud3 starting screen probably indicates a configuration error. Check Configuration > Logs and see if any are listed.

So I guess you have track_devices parameter with ‘iphone_11_van_bob’? What is the mobile_app device tracker entity name. It should be something like ‘iphone_11_van_bob_2’

bobvmierlo commented 4 years ago

Okay I got the integration to start now, but the tracking is still not working. See screenshots below:

eventlog (removed my emailaddress from the screenshot): image

config_ic3.yaml: image

bobvmierlo commented 4 years ago

I also noticed that although I have set waze_region: EU the following entry in the eventlog card is stating it is using US. Set Up Waze > Region-US, MinDist-1.61 mi (2.59km), MaxDist-1609.35 mi (2590.0km), Realtime-False

rdstodda commented 4 years ago

I am also getting the notify error. It seems that icloud3 is starting before HA is ready on my system. I get it running by manually calling the device_tracker.icloud3_restart service. Is there a way to pause Icloud3 or have it retry?

bobvmierlo commented 4 years ago

Okay, I got it to (kinda) work by moving the track_devices to my configuration.yaml instead of the config_ic3.yaml. The integration still needs to be restarted by the service call since the initial boot allways fails. After that the eventlog card shows several actions, but the integration does not create a single sensor.

Also getting these errors over 400 times in the HA log:

Logger: homeassistant.components.device_tracker
Source: components/device_tracker/legacy.py:184
Integration: Device tracker (documentation, issues)
First occurred: 4:34:21 PM (277 occurrences)
Last logged: 4:34:45 PM

The see service is not supported for this entity device_tracker.iphone_11_van_bob
The see service is not supported for this entity device_tracker.iphone_van_linde
bobvmierlo commented 4 years ago

Don't know what you've changed, but RC11c works like a charm and fixes a lot of my issues. I do however still get loads of the errors saying the 'see service is not supported'.

gcobb321 commented 4 years ago

The big thing is iCloud3 now checks if an authentication & verification is needed when starting rather than on the first location request. I think you were getting killed setting up devices the first time so iCloud3 would never load correctly.

Who is generating the errors in the ‘se’ service error. The HA log files might point to the problem area

bobvmierlo commented 4 years ago

It seems like iCloud3 is using the device_tracker.see servicecall and it's calling the complete entity_id instead of just the part after the 'device_tracker'. The device_tracker.see service however doesn't accept that as a service call, it needs an entry like dev_id: iphone_11_van_bob. As a result i'm getting this error in the HA log for hundreds of times.

Log Details (ERROR)
Logger: homeassistant.components.device_tracker
Source: components/device_tracker/legacy.py:184
Integration: Device tracker (documentation, issues)
First occurred: 9:02:38 PM (1247 occurrences)
Last logged: 9:05:30 PM

The see service is not supported for this entity device_tracker.iphone_11_van_bob
The see service is not supported for this entity device_tracker.iphone_van_linde

Also I noticed that the v2.2 integration does a famshr or fmf update even when the companion app doesn't return any location info, which is good and the v2.1 used to do this aswell. But even when the eventlog shows that the tracked device is 'home' the entity state of the tracked device stays on 'Unknown'. The "old" v2.1 integration used to set the tracked device to the latest acquired state, which in this case would be 'Home', not 'Unknown'.

image image

bobvmierlo commented 4 years ago

Don't know if it's related, but i'm getting the following error aswell when restarting icloud3

Log Details (ERROR)
Logger: custom_components.icloud3_dev.device_tracker
Source: custom_components/icloud3_dev/device_tracker.py:4579
Integration: icloud3_dev
First occurred: 9:17:49 PM (1 occurrences)
Last logged: 9:17:49 PM

local variable 'notify_devicename' referenced before assignment
Traceback (most recent call last):
  File "/config/custom_components/icloud3_dev/device_tracker.py", line 4569, in _send_message_to_device
    for notify_devicename in self.notify_iosapp_entity.get(devicename):
TypeError: 'NoneType' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/icloud3_dev/device_tracker.py", line 2977, in _request_iosapp_location_update
    return_code = self._send_message_to_device(devicename, message)
  File "/config/custom_components/icloud3_dev/device_tracker.py", line 4579, in _send_message_to_device
    event_msg = (f"iCloud3 Error > An error occurred sending a message to device "
UnboundLocalError: local variable 'notify_devicename' referenced before assignmen
bobvmierlo commented 4 years ago

Solved a few errors by making sure the tracked devices are in the known_devices.yaml file. Although this file has been decrepated since a few HA versions ago, so the phones where not in there anymore since I did a fresh install recently where I cleared that file of unnecessary entries. The errors stated above are all gone, so no more hundreds of errors from the .see servicecall. And the device_tracker states goes to Home from Unknown.

But like it goes while bug solving a beta/RC version, here are some new errors:

Log Details (ERROR)
Logger: custom_components.icloud3_dev.device_tracker
Source: custom_components/icloud3_dev/device_tracker.py:1599
Integration: icloud3_dev
First occurred: 9:36:15 PM (56 occurrences)
Last logged: 9:40:50 PM

'battery_level'
Traceback (most recent call last):
  File "/config/custom_components/icloud3_dev/device_tracker.py", line 1599, in _polling_loop_5_sec_device
    ic3dev_battery                = iosapp_dev_attrs[ATTR_BATTERY_LEVEL]
KeyError: 'battery_level'
Log Details (ERROR)
Logger: custom_components.icloud3_dev.device_tracker
Source: custom_components/icloud3_dev/device_tracker.py:8133
Integration: icloud3_dev
First occurred: 9:36:15 PM (56 occurrences)
Last logged: 9:40:50 PM

Device Update Error, Error-<class 'ValueError'>
gcobb321 commented 4 years ago

I’ll look at the notif_devicename error. Check Stage 2 and 3 of the Event Log to see what devices are being monitored. The battery_level is an attribute of your mobile app being monitored And if there is an error with the mobile app device tracker entity, the battery_level will not be available, leading to the error message.

gcobb321 commented 4 years ago

I just updated to rc11d which I think will solve this problem by using the iC3 location data when the ios app location data is not available during startup.

bobvmierlo commented 4 years ago

So far everything works fine, I think the battery error is because my wife has set the app permissions all to disabled. And by design the app only sends sensor data when the location get's updated within the app, which in her case never happens.

bobvmierlo commented 4 years ago

Unrelated to this, but I was wondering and didn't want to make a whole new issue for this.

The eventlog shows the following entry: Set Up Waze > Region-US, MinDist-2.59 mi (4.17km), MaxDist-2590.0 mi (4168.21km), Realtime-False

While my ic3_config.yaml has this:

#--Waze Parameters-----------------------------------------
distance_method: waze
waze_region: 'EU'

This confuses me, is it using US region or EU?

bobvmierlo commented 4 years ago

Also both 'TravelTime' and 'WazeDist' are behaving strange. 'TravelTime' is empty all the time, and 'WazeDist' is on 'DistLow' all the time. Any issue with the Waze part of the integration?

gcobb321 commented 4 years ago

Waze is not used when the calculated distance from Home is less than 1km or the value in the waze_min_distance parameter. DistLow is displayed in the Waze field and, since Waze is not being used, there is no TravelTime to display. When less than 1m, iCloud3 uses the calc_method because requesting the info from Waze at short distances affects the timing of the interval calculations and usually results in bad information, which, in turn, screws up everything else.

I have found a problem with the EU Waze region code not being decoded properly (internally using lower case when testing for uppercase). It's fixed in RC11e.

bobvmierlo commented 4 years ago

Though even when i'm way beyond the 1km limit the waze distance and traveltime won't do anything. For example my job is 25km away, but the traveltime is empty and wazedist is allways on DistLow. This used to work fine in v2.1, and I haven't changed anything in my config params.

But maybe this is fixed when the region is properly decoded.

gcobb321 commented 4 years ago

I wonder if any data is being returned from waze and DistLow is being displayed instead of an error message. Waze adds log records to the HA Log file. Would you look there and see if there are any.

Example of when I was out this morning:

2020-08-25 09:42:25 INFO (SyncWorker_1) [custom_components.icloud3_dev.device_tracker] Request Waze Info, CurrentLoc to home
2020-08-25 09:42:25 INFO (SyncWorker_1) [WazeRouteCalculator.WazeRouteCalculator] From: 27.69879150390625,-80.37367735752738 - to: 27.726639,-80.390456
2020-08-25 09:42:25 INFO (SyncWorker_1) [WazeRouteCalculator.WazeRouteCalculator] Time 6.90 minutes, distance 5.39 km.
2020-08-25 09:42:25 INFO (SyncWorker_1) [custom_components.icloud3_dev.device_tracker] Request Waze Info, CurrentLoc to LastLoc
2020-08-25 09:42:25 INFO (SyncWorker_1) [WazeRouteCalculator.WazeRouteCalculator] From: 27.721908569335938,-80.37942828122578 - to: 27.69879150390625,-80.37367735752738
2020-08-25 09:42:25 INFO (SyncWorker_1) [WazeRouteCalculator.WazeRouteCalculator] Time 4.68 minutes, distance 2.67 km.
bobvmierlo commented 4 years ago

I have no such entries in my HA log, would I need to set icloud3 to debugging log level?

gcobb321 commented 4 years ago

No. Waze always writes those entries. I updated iCloud3 to RC11e to address your EU Waze issue. Try that version and see what happens.

bobvmierlo commented 4 years ago

Everything works like a charm now! Also updated to the f version to fix the 4hr bug. p.s. you forgot to change the version in the device_tracker.py for version f ;)