I have a setup where the telephone number of incoming calls is distributed via MQTT and picked up by a sensor in my home assistant instance. The state of this sensor is either just empty or the telephone number if there currently is an incoming call.
Now I want to achieve the following, but do not really have an idea how to solve this: There should be a list in my lovelace interface showing me the last x incoming calls (telephone number + date/time).
Is there any way to generate such a list e.g. from the history? (only showing states where the state is not empty displayed in the form of a list)
Here is an automation I use that saves the states of the last 10 motion detection events into a history of a variable. You should be able to easily modify it for your use.
You’ll need to install a custom_component in order to use this but it works pretty well.
Thank you both for your ideas. I implemented the approach presented by @tom_l but came accross one difficulty:
The Home Feed Card allows me to specify an id_filter to only show persistent notifications matching that filter. However, I do not understand how to create appropriate notification IDs with the persistent_notification.create service. From the docs it seems as if I can only specify a “fixed” ID, but not a prefix (e.g. “call_log_”) to filter for the relevant notifications in the Home Feed Card. Do I miss something here? Can you give me an indication on how to create the notifications with IDs that can be filtered by the id_filter?
- service: persistent_notification.create
data_template:
message: "{{ now().strftime('%H:%M %A %d %B %Y') }} - The phone was called from {{ trigger.to_state.state }}"
title: "Phone Call"
notification_id: "call_log_{{ as_timestamp(now()) }}"
It will have a prefix of call_log_ you can use to filter the home card. The timestamp as the rest of the ID will be unique so messages will not be overwritten.
EDIT: Hmm. Maybe not. From the docs:
The persistent_notification integration supports specifying templates for both the message and the title .
It does not say that the ID can’t be templated but not mentioning it there is ominous. Give it a go. If it does not work there is good cause for a PR to get this included.
EDIt2: Just had a look at the source for the persistent notification. The ID can not be templated:
So there goes that idea. The options I see are to put in a pull request to get the ID to support templates and hope someone with the time and skill can do it, or go with @finity’s idea.
I tried to use Home assistant variables component to save historical/last value of the backup, unfortunately I failed after few hours trial and error approach:
The goal is to save backup results communicated via mqtt message after subsequent HA reboot
(mqtt after reboot is not longer available).
OK, I haven’t looked at the variable integration in a while.
First, that version of the custom integration (by rogro82) hasn’t been updated in over two yesrs now. So, first I recommend using the one by @Wibias found here instead. It was updated to account for changes in the way HA handled templates (I think that was why…).
After you change to that version and looking at my config for examples I think you need to try this:
alias: gDriveBackupStataus
description: Record state of last Google Drive Backup
trigger:
- platform: state
entity_id: sensor.google_backup_results
condition:
- condition: template
value_template: >
{{ trigger.to_state.state not in ['Unknown'] }}
action:
- service: variable.set_variable
data:
variable: lastbackup
attributes:
fileCount: '{{ trigger.to_state.attributes.fileCount }}'
backedUpCount: '{{ trigger.to_state.attributes.backedUpCount }}'
value: '{{ trigger.to_state.state }}'
mode: single
SOLVED
Thank you for your support, now it works, without any problem. The old hacks repository apparently does not work with new HA version even with the right spelling