How to capture the schedule that was connected to a certain device.
I am trying to know the schedule that this device was connected. Any direction?
{{ states.input_boolean.sonoff_switch_6}}
<template state input_boolean.sonoff_switch_6=on; friendly_name=Cafeteira, icon=mdi:coffee-outline @ 2018-07-04T19:03:42.137209-03:00>
I have the following exit. But how to know exactly when it was connected. It only displays the time that changed the status. Even so I do not know how to isolate only the date.
states.input_boolean.sonoff_switch_6.last_changed is the date & time it last changed. If it is on, then this is the date & time it was last switched on. (Of course, if it’s currently off, then this is not the date & time it was last switched on.)
So, is {{ states.input_boolean.sonoff_switch_6.last_changed }} what you’re looking for?
Or, if you want the date & time it was last switched on, regardless of whether or not it is currently on, then I think you’ll need an automation and an input_datetime to store the date & time in. E.g.:
input_datetime:
switch_last_on:
name: Last time switch turned on
automation:
- alias: Record last turn on date & time
trigger:
platform: state
entity_id: input_boolean.sonoff_switch_6
to: 'on'
action:
service: input_datetime.set_datetime
entity_id: input_datetime.switch_last_on
data_template:
date: "{{ now().date() }}"
time: "{{ now().time() }}"
I do not know if I understand. I’ll try to do it later.
I think getting the schedule of the change already helps me. For she will switch from off to on.
I want to read in a tts, where it says that the coffee was prepared at XX: XX.
So. Picking up the schedule that was changed will work out.
- data_template:
message: 'Iniciei o preparo do seu café ás {{ states.input_boolean.sonoff_switch_6.last_changed }}'
entity_id: media_player.living_room_speaker
service: tts.google_say
So you want the time it last changed, something like ‘19:03’? Then I would suggest this:
- service: tts.google_say
entity_id: media_player.living_room_speaker
data_template:
message: "Iniciei o preparo do seu café ás {% set t=states.input_boolean.sonoff_switch_6.last_changed %}{{ t.hour ~ ':' ~ t.minute }}"
Actually, that will give the time in UTC. Give me a few minutes to suggest something else that will give the local time of the last change…
So, there still might be a better way to do this, but this should at least work:
- service: tts.google_say
entity_id: media_player.living_room_speaker
data_template:
message: "Iniciei o preparo do seu café ás {{ as_timestamp(states.input_boolean.sonoff_switch_6.last_changed)|timestamp_local|regex_findall_index('[0-9]+:[0-9]+') }}"
Thanks for your help!
I’m breaking my head now with “if” and “else”. user @petro has helped me.
Now I’m trying, take a look at this topic. Can you help me … It’s part of this automation.