I’ve created a custom event fired via the REST API. I have a crummy IP Camera that can hit an endpoint when it detects motion. It hits a URL like so:
POST https://homeassistant/api/events/event_camera_motion
This works great and I can use automation to do certain things like send notifications and take a snapshot from the camera.
But! How can I record this custom event in the History view? I’d like to see historical logging of when these events have fired. I have no idea how to display a custom event in the logbook or history views.
Help appreciated! Thanks!
For Logbook entries, you can use the service documented here. You can just add another step to your existing automation that is triggered by your custom event.
For history, hmm, good question. My gut says to create an input_boolean, and have an automation that is triggered by the custom event turn the input_boolean on, then delay a few seconds, then turn it off. I suppose this could also be added to your existing automation.
Or, better yet, you could invoke a python_script from the automation that sets a state, say, binary_sensor.motion_detected, to ‘on’, with an attribute named ‘device_class’ with a value of ‘motion’, then waits a few seconds and sets the state to ‘off’ (with the same attribute.)