Determine how a switch (Shelly 1) was turned on?

This might be a really obvious thing I’m missing or it may simply be impossible…
I have a Shelly1 which can be triggered by physical switch or by an automation (or Alexa)

I’d like to take an action based on if it’s physically switched (only) - is there any way to determine this?


1 Like

So in summary… “maybe, but probably not”

No, there are many answers. You should spend some time reading. The answer is there.

I think I can take a guess at it actually

Appears that if I use the physical switch on the Shelly1 it doesn’t give a “triggered by” in the device history, so I should be able to use that fact

Sadly this is also the case with using Alexa (although I wonder if I could use a helper instead to track that)

Need to do a bit more reading as I can’t see how I can grab the triggered_by in NodeRed right now, but guessing it’s possible

Edit, looks like grabbing payload.new_state.context.user_id will give me a null value or an encoded UserID for the Shell1 depending on how it’s turned off…

Have a look at this: Work with "Triggered by" in automations - #8 by 123.

Yeah, I looked at that and ran my own tests - my table didn’t match
I never get a ParentID on any route. On automations (at least using my nodeRed setup) they are triggered by Supervisor user
The best I can do is distinguish by user being null or not, null being Alexa or Physical

Correct. Node-Red is external to Home Assistant so whatever work it performs is labeled with the generic reference “Supervisor”.

This completely changes the original request. Maybe there’s a way to inject the additional context you need from NR and use that in HA.

It really doesn’t change the original request at all? The request was to know how the switch was turned on (physical, alexa or automation)
I don’t actually need to know anything about nodeRed (although I do as I noted about)

I have Physical/Alexa or automation, but no way to separate the physical/alexa (although I will sort that out with a helper)

I think there is a kind of solution: If you create template switch that activates the actual switch you can then use the template switch in your automation, but in the l UI, you define the actual switch…

Yeah, I think that’s the only way at this point, and what I’m planning on doing (with the helper) if I need to - at the moment the physical/Alexa combined knowledge is proving enough