Random “turned on/off by service homeassistant.turn_on/off” on many switches at once

I have a very strange error, where a bunch of switches (and lights) turn on/off - the logbook says “turned on/off by service homeassistant.turn_on/off…

It has happened three times in last two days, the only thing I’ve changed recently that I could imagine would be setting up a complex climate/thermostat - but it’s mostly scripts and a couple of automations which only touches the climate device, a couple of helpers and reads sensor data…

Otherwise I’ve got no clue, the logs don’t seem to offer any help… I’m on latest versions on all integrations and packages: VM running Hassos, newest HA, have default MQTT server, zigbee2mqtt, esphome, and harmony integrations (i think these are where all the affected entities are).

Any guidance to a) see what triggered the service call, or b) stop the ghost??!

I’m really struggling with this. If anyone can offer guidance where/how to check what/who triggered a service homeassistant.turn_on for a random assortment of switches in various integrations (mqtt, helpers, template switches, everything!!) all at the same time, maybe once a day now (just not a specific time)…

I can’t see any automations have been triggered, and the logs don’t suggest anything’s causing issues.

Is there somewhere else I can look or have you heard of anything like this before? Not sure where to look in troubleshooting.

You can start by using this card to display recently triggered automation (made by Taras)-

OR

You can also go to Developer Tools —> Devices —> Find and click your troubled device —> You will see the associated automation to that specific device —> Inspect the automation

Thanks for the ideas. No luck here I’m afraid…

Some of the devices are not linked to any automations - and no automations were triggered in the time at/before the big load of homeassistant.turn_on (and off sometimes) service calls.

That’s where you need to start your investigation. If you want help with debugging, post all parts of the “complex climate/thermostat”.

Thanks for this - the main automation is ‘complex’ (for me!) as it takes triggers and conditions about occupancy states and some averaged temp sensor values to decide what temp to set the thermostat to or which schedule to enable/disable… Other associated automations I made for this just change what is visible in the dashboard.

The actions this main automation triggers are all solely linked to i) the one climate entity, which uses a zigbee plug as the heater (while testing) and ii) a handful of schedules in the custom scheduler integration…

I’m not sure of the value of sharing the code of the template sensors or automation at this point, and it will be another day before i get to a computer, as I’m certain the automation doesn’t have any trigger linked to any of the devices which have been turned on. However, I can now see it may be the custom integration playing silly with other devices, rather than the automation itself - so i’ve disabled this integration and will wait to see if I get any more switch issues…

Thanks for the tip off, I hadn’t thought this integration could be a problem - i’ll be sure to come back with the code of the automations, sensors, etc, i recently added if this doesn’t stop the issue.

To conclude, this was an issue in the scheduler integration/card - It has gone now I removed these from HA… Surprised, to be honest, that it managed to flip all kind of switches at random times … despite only giving it access to the one entity… I’ll follow up with the maintainer.

Thanks @123 for pushing me onto the right track - I think I just didn’t see anything in the automations which could have caused this… knocked some sense into me!! Cheers

I have the same problem!
Also using the scheduler card and i receive weird logs when ‘service homeassistant.turn_on’ triggers a boolean switch which causes my heatpump to start…

I had a similar problem with exterior lights, that I use for security, “randomly” turning off in the middle of the night.
I found a Logbook entry stating:

Amazon Alexa sent command Alexa.PowerController/TurnOff for Outside Lights Light: Turn off

I went into my Alexa app and found

Alexa had a hunch that you were asleep and the light is usually off at this time.

Well, I don’t know where it got that idea, because those exterior lights were never off until Alexa got a hunch.

Anyway, to fix the issue I disabled the hunches by going to the More menu (icon looks kinda like a hamburger menu icon) > Settings > Hunches (near the bottom) > Settings (gear icon in the top right) > Automatic Actions > Lights > Turn off the lights if you’re asleep.

I doubt this is what caused the problem for the folks above because I suspect Hunches are newer, but I hope this can help others that stumble across this topic in the future.