How to capture the schedule that was connected to a particular device?

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.

Sorry, not exactly sure what you’re trying to do. Do you want just the date of the last time this entity changed? If so, you could do it like this:

{{ states.input_boolean.sonoff_switch_6.last_changed|regex_findall_index('[0-9]+-[0-9]+-[0-9]+') }}

Given the state change you showed above, it would return 2018-07-04.

Thanks for your help.
What I’m trying to get is the time the device was switched on.

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() }}"
1 Like

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.

With the

{{states.input_boolean.sonoff_switch_6.last_changed}}

Do I have the time?

Here’s how I’ll try it later.

- 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

it would be maybe

{{states.input_boolean.sonoff_switch_6.last_changed.timer}}

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]+') }}"
1 Like

Thanks for your help!
How can I know the parameters that I can remove from a device.

for example did you put “last_changed” as you know there is such a possibility? Which way ?

See:

1 Like

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.