Get time of last switch usage

Can I find when the last time a physical switch (inovelli lzw31-sn) was used?

I see there's lastEvent and lastActivity in Custom Attributes, but neither of these are what I'm looking for.

I can't use lastActivity because that updates for reasons besides state change (like when it reports on energy).

I can't use lastEvent is because if in the beginning of the rule the lastEvent was TapUp, then someone tapped up again, lastEvent at the end of the rule will still simply show TapUp-- I wont know that someone has pushed a button on the switch.

in the device's Events page, the lastEvent row has a Date field-- can i test against that (or save that as a variable) ?

1 Like

You could do this with a custom app if the history is still there (no guarantee that there will be; you can set the history very low). However, it would be pretty easy just to do with a rule instead. I'd create a hub variable (Settings > Hub Variables), then create a rule like:

Trigger: Inovelli switch *changed* (use the "Switch" capability when creating this trigger)

Then, in Actions to run, just set the hub variable to the current time or whatever you want. If you're using a string or number variable, you could use %now%; if you're using a DateTime variable (probably what you want), you can just set it to the current date/time with the dropdowns.

When you're all done, hit "Done" (or "Install Rule"--same thing, just keeps the rule open).

2 Likes

hub variable + rule = great solution. thanks.

So I'm finally setting this up and it's not behaving at all how I expected.

If i use "switch changed", then the RM only triggers when changing state. for example, if the light is on, and i press the up (on) button, the rule does not trigger. this makes sense-- nothing has changed.

"switch changed" also does not catch dimming events. makes sense again. so i also need a dimmer changed.

but even both together don't catch double (or triple or ...) taps. so i need a trigger for every button device too.

That's 15 triggers just for one switch. and lots of switches. any easier way to do that?

For the button events, you should just be able to use "pushed changed" and "held changed," not every button event/number individually (and you can ignore "released" because it won't happen without one of the others). You might need to use a "custom attribute" trigger to do this--don't recall off the top of my head, and I don't normally use RM for this (I'd recommend Button Controller for most "real" automations instead--but not this one).

yep, looks like having the two custom attribute triggers gets the job done. way better than 15!

thanks.

Download the Hubitat app