I am trying to use the developer tools Events tab to fire some events, specifically to simulate a device tracker entering and leaving zones to test various automations. I am unable to do it correctly and I get an error in the log viewer. Maybe someone can help me get it right?
I am using state_changed as the event, and here’s the event data:
entity_id: person.felipe
old_state: Home
new_state: Away
and here is the log output:
2020-02-19 00:05:19 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback async_track_state_change.<locals>.state_change_listener(<Event state_...ew_state=Away>) at /usr/src/homeassistant/homeassistant/helpers/event.py:81
Traceback (most recent call last):
File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 92, in state_change_listener
old_state = old_state.state
AttributeError: 'str' object has no attribute 'state'
Traceback (most recent call last):
File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 92, in state_change_listener
old_state = old_state.state
AttributeError: 'str' object has no attribute 'state'
Traceback (most recent call last):
File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 92, in state_change_listener
old_state = old_state.state
AttributeError: 'str' object has no attribute 'state'
I am making some complex automations based on locations, and I would like to test them without walking all over town, so I want to trigger a state_change event for my person or device tracker, so that it will trigger the automation for testing purposes.
Hey @code-in-progress - that seemed like just the thing, but unfortunately unsupported for my device according to the logs (a OnePlus 7Pro running the HA android app for location services):
2020-02-19 10:11:41 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1832370352] Received {'type': 'call_service', 'domain': 'device_tracker', 'service': 'see', 'service_data': {'dev_id': 'gm1917', 'location_name': 'not_home'}, 'id': 23}
2020-02-19 10:11:41 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=device_tracker, service=see, service_data=dev_id=gm1917, location_name=not_home>
2020-02-19 10:11:41 ERROR (MainThread) [homeassistant.components.device_tracker] The see service is not supported for this entity device_tracker.gm1917
@Burningstone I was trying to use the call service button under developer tools - see the service data I used in my original post
That’s odd! It works for almost all the other device trackers. I wonder if it’s something to do with the HA app? When I run it against any of my other device_trackers (nmap and life360), it works fine.
You might want to raise an issue on github as I don’t think this is the way it’s supposed to work.
Yea, maybe it has something to do with the app being relatively new? I will raise it in github. In the mean time, any ideas about what I a doping wrong with just trying to fire off state_changed?
Honestly, I think it’s the same thing. state_changed may not be functioning correctly due to something to do with the app and the way it’s exposing it’s event model.
although now looking at the docs on state object and my error, it seems that the problem is that I am just passing a string for the state, whereas it should be an object: https://www.home-assistant.io/topics/state_object/
Let me try and see if I can udnerstand that
I hate to revive this old topic, but I’m attempting to do the same sort of automation troubleshooting - simulating leaving a zone to trigger automations for debugging/trial-and-error purposes so I don’t have to actually keep leaving my house and coming back. I copied your event data example and replaced your device_trackers with the trigger entities in my automations that I wish to test, then fire the event. The interface reports:
Event state_changed successfully fired!
But…nothing happens. I know the automation works since if I actually leave my house/zone, then it triggers properly. In this case, all I have it doing right now for simplicity’s sake is to just push a notification to the homeassistant app telling me goodbye, but once I get the basics on this down I’d like to expand on both it and events for when I return.
I also tried the suggested device_tracker.see option, but I got the same unsupported device message, so no go there. For what it’s worth, the documentation mentions that simply adjusting the device_tracker state on the STATES tab should produce the same effect, yet it too does nothing:
For example, changing the light.bedroom state from off to on does not turn on the light. If there is an automation that triggers on the state change of the light.bedroom, it will be triggered – even though the actual bulb has not turned on.
I would appreciate your assistance and time in helping me figure out what I might be doing wrong.
Excellent suggestion, thank you! Works perfectly in that way, so I think I’m set! It’s still interesting that the developer tools doesn’t appear to be working properly, but perhaps that can be left for another day.