I have Sonoff Door sensors (The kind that only gives “Open” state) hooked to a Sonoff RF bridge.
I have 4 doors connected to this RF bridge.
This is all working well with the AlexIT Sonoff repo and I have a card displaying the last state received.
What I would like to do is to have a card in Lovelace displaying a history of all the doors triggered with the date and time stamp.
I had a look at the state_attr “name:” which gives me the name of the door that was triggered but I am not sure how to go about displaying a history of let’s say the last 20 triggers with the date and time stamps.
Is anyone able to assist with something like this?
Currently, this is my config:
configuration.yaml
sonoff:
username: [email protected]
password: ************
force_update: [temperature, power]
scan_interval: '00:05:00' # (optional) default 5 minutes
sensors: [temperature, humidity, power, current, voltage]
sonoff:
rfbridge:
Door sensor:
name: Door Sensor with one state # optional, you can change sensor name
device_class: door
timeout: 5
Under Developer Tools I have the sonoff.remote with Attributes:
type manufacturer: Sonoff
model: RF_Bridge
sw_version: PSF-BRA-GL v3.4.1
command: 1
ts: 2020-07-17T14:33:50.000Z
name: Front Door
friendly_name: Door Sensor
supported_features: 1
So I would imagine that I would need the “name:” and “ts:” attribute to get this to work but have no idea from here.
I don’t know if there is an easy way (or even possible) to do it using built-in stuff but I do the exact thing you want to do using a custom component.
then after the variable is created then you can use the variable in a lovelace card to display the history. It also uses a custom lovelace card - entity-attributes-card:
@finity - Thank you for the solution above, but I am not winning with this one. I am getting lost at the part of the trigger as well as the automation section. I do not have the door sensors as entities (if that makes sense). I only have one entity called “remote.sonoff_10007c5697” and then it is within it’s state_attr that it mentions which door was opened. Please have a look at the image below of the remote.sonoff entity:
Other than this I have built an automation that broadcasts to my Google mini device when a door opens and the automation for that looks like the below:
- id: '1592847168444'
alias: Announce Door open status
description: ''
trigger:
- event_data: {}
event_type: sonoff.remote
platform: event
condition:
- after: '20:00'
before: 06:00
condition: time
action:
- data_template:
command: The {{ trigger.event.data.name }} has just been opened
service: rest_command.assistant_broadcast
{{ trigger.event.data.name }} basically just says the name of the door for example “Garage Door”.
I hope the above automation code is enough to give you an idea as to how the system knows which door was opened and how I can use my current code to store the {{ trigger.event.data.name }} with the time stamp which is “ts:” in the attributes as shown in the image above in the variable. I have fixed the date and time stamp to show correctly in my local time and not UTC by creating the below value template:
So I have the Name of the door as: {{state_attr(‘remote.sonoff_10007c5697’,‘name’)}}
and I have the date / time stamp as : {{ as_timestamp(state_attr(‘remote.sonoff_10007c5697’,‘ts’))|timestamp_custom(’%Y-%m-%d-%H:%M’) }}
Maybe with the info above you will be able to assist me on how I can adapt your code to make it work for me. Apologies but I am a bit stupid with these things, but I would really like to learn.
The “variable.last_triggered” is the entity that you want to show the data from and “history_1, history_2, etc” are the attributes you want to display.
One thing to check is if there is an entity called “variable.last_triggered” in your states view under developer tools that has a current valid state (which should be the name:timestamp of the last triggered event) and then make sure it has all of the attributes for history included in it under the “attributes” tab.
Hi and thank you for your assistance.
There is the variable called variable.last_triggered under the states but it only has the state listed as Not set as per image below.
Not sure where I went wrong but I will go through it all once more to see where I could have messed something up.
for some reason the set_variable service isn’t running correctly from the automation.
Are you sure the trigger is working correctly? Does it contain the data in the “value” template?
Since there are no attributes set I believe the trigger is possibly the cause of the malfunction. If it was triggering you should probably have a bunch of attributes that all say “Not set” since the first thing it does is sets each attribute in a cascade from the previous state/history.
Thank you so much finity for all of your help. You were correct that the variable was never set. You pointed me in the right direction to have a look at the variable.last_triggered 's attributes to see that it shows the history attributes. Once I knew where to look, I redid the automation code and confirmed that the attributes were now showing. Once that was done, I rebuilt the Lovelace card and all was well. I am now able to see the state history of all my door open events.
Hi, I try to use your integration. First, I couldn’t install the integration, HA won’t restart but finally I found I had to add version to manifest.json.
In my configuration.yaml I added:
It seems ‘initial_state’ is no longer supported so I made a comment line for it.
As you see in my automation I have 4 motion sensors. When motion is detected the state goes from ‘off’ to ‘on’, this is checked in the Developer Tools:
Unfortunately the variable_last_motions remails ‘Not set’: