Was floating the idea of creating a dashboard with some toggle switches on it that can keep track of time that the switch is turned on and send me an email when it's turned off. My initial thought is just a toggle switch with a history_stats entity monitoring the state of the toggle switch entity. Curious what your thoughts on this kind of setup would be
#Dashboard with Toggle switches for time tracking
1 messages · Page 1 of 1 (latest)
Might not need history stats. Here's a simple example automation that will tell you how long a input_boolean was turned on for when you turn it off.
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.boolean1
from: "on"
to: "off"
condition: []
action:
- action: persistent_notification.create
metadata: {}
data:
message: "{{ trigger.to_state.last_changed - trigger.from_state.last_changed }}"
title: Toggle Time
mode: single
You can modify to send yourself an email.
Man this is a lot to jump into lol
looks like I can't extract the friendly name of the trigger, is there a different way to do it other than adding trigger.entity_id.friendly_name to the message string?
Take the entity_id, and look it up in the states object:
states[trigger.entity_id].attributes.friendly_name
Sweet, thank you. I was able to add email notifications and a google sheets append action for logging.
Now I have noticed just during testing that automations don't always fire if I toggle off multiple switches in a short time period. Is that just a limitation of automations or is that a configuration issue?
man, im solving all my problems, it was set for single mode. changed it to parallels
Parallel can get a bit wonky when setting state of the same entity. Personally, I’d go with queued. That will act as a FIFO (first in, first out) queue and you will always have the latest last changed. Especially if toggling in rapid bursts.
I'll switch it to queued. It is going to be multiple different entities though, not just a single button, rarely if ever will a single switch be toggled more than once or twice a day
Ah, if that’s the case, then leave it as parallel and see how that works for you. I thought you were working with one or two entities.