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
73.54k stars 30.72k forks source link

Event "call service" "see" is not fired or logged on the device tracker platform #23795

Closed coxtor closed 5 years ago

coxtor commented 5 years ago

Home Assistant release with the issue:

arch x86_64
dev false
docker true
hassio false
os_name Linux
python_version 3.7.3
version 0.92.2
virtualenv false

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.): Docker

Component/platform: platform: device_tracker components. fritz, nmap and possibly other device tracker platforms

Description of problem: I have an automation that should be executed every time a device is “seen” . However, the automation is never executed. When manually firing the device_tracker.see service with mock data in the home assitant interface the automation works fine.

Otherwise the device tracker works well and reliable, for presence detection.

No errors occur.

Furthermore when analyzing the home assistant.db it shows that the service is never logged, except, when called manually. However, the service is registered multiple times.

Excerpt of the db:

Service registered entry: "98503" "service_registered" "{""domain"": ""device_tracker"", ""service"": ""see""}" "LOCAL" "2019-05-03 05:32:43.082224" "2019-05-03 05:33:02.843096" "fcde4b5ce5e1462383bdbbd56d1809ca"

Manually triggered event in web-ui

Mock data: {"dev_id":"device", "location_name":"home"}

Corresponding database entry: "226942" "call_service" "{""domain"": ""device_tracker"", ""service"": ""see"", ""service_data"": {""dev_id"": ""redmi_note_5"", ""location_name"": ""home""}}" "LOCAL" "2019-05-09 12:13:10.476427" "2019-05-09 12:13:10.497045" "a5ebf98b12824269a6a4f0318c97a223" "ef49cf62bc7b44f0ae88b9bf8c3ad62c"

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

- alias: Unknown Network device connected
  trigger:
    platform: event
    event_type: call_service
    event_data: 
      domain: device_tracker
      service: see
  action:
    - service: system_log.write
      data_template:
        level: info
        message: >-
          {% set x = trigger.event.as_dict()['data'] %}
          DATA: {{ x }}, ENTITY_ID: {{ x.service_data.dev_id }}    

Traceback (if applicable):

Additional information:

This behavior has been verified on a second local home assistant instance using the nmap and fritz component.

As a further remark: Testing the call service event using the identical automation with a different platform

      event_data: 
      domain: light
      service: turn_on

works flawlessly.

pnbruckner commented 5 years ago

This is normal.

Device tracker platforms work directly with the device tracker component and do not call the device_tracker.see service. Consequently, when they "see" a device, the service is not fired, and hence you won't see a call_service event.

If you want an automation to fire when a device is seen/updated, then you should probably be using a state trigger.

coxtor commented 5 years ago

Thank you