Need help with button logic

I'm trying to control an Aqara mini switch button so that if I press it, the music starts playing. Then if I press it again, it stops playing. It works fine to start Sonos music. I'm trying to use logic to determine if the switch is on (Sonos - Office Fave 1), then play the music, if not stop playing the music. For some reason the "IF (Sonos - Office Fave 1 is off) never executes. Only the "is on" part of the IF statement. Note I included some items like the office lamp off or office fan off to determine if that part of the block executed.

Any idea why the "is off" if statement is never executed?

What steps from the documentation on how to troubleshoot apps have you followed? If you are having trouble following a specific step, please share details here, and someone can help.

As noted in this doc and nearly every similar previous post (1, 2, 3, and others), logs are the #1 troubleshooting tool for things like this. The document above suggests this and shows you an example of how to enable them and what they look like. You can share a screenshot of them here if they are not helpful for you, as they will be helpful to others helping you troubleshoot.

4 Likes

Both "is off" and "is on" have the same Off: Office Fan action so that won't be helpful to debug what you're experiencing. Make one On.

Additionally, your nested conditional logic is redundant. If Office Fave 1 isn't off, it'll be on and no additional check is needed in the ELSE.

1 Like

Good point. There are a lot of errors in the app log. Not exactly sure how to interpret the errors.

It won't shut off even with this statement. It just keeps turning the button on and I have to cancel the music with my voice. Now if I go to Devices I can turn off and on the "Sonos - Office Fave 1" device.

image

Have you considered the “toggle switch” action?

It will handle the logic you’re describing above without you having to create conditional statements within the action of the rule.

2 Likes

Isn't this a button?

Thanks I just tried toggle and it didn't work. It's like it's determined to only turn on the switch. But as I said before I can turn it off and on in Devices" I just thought it would be nice for my wife to be able to shut the music off with the button as well.

image

If you haven't done this already, I would delete this button rule and create a new one and see if that works. I would also try to create a RM rule and see if that works.

Yes, made with Button Controller 5.1.

Ah, sorry, my mistake, I forgot that you had a different device as the button device and the switch inside the actions. I thought you wouldn't be able to switch a button device on or off, but they are different devices.

Perhaps try a custom command instead, running the on or off commands.

Thanks, I'll try that as well. I just deleted and created a new button and off/on and toggle did not work to stop it.

How about trying this simple Toggle with a super basic device like Office Fan or Office Lamp?

That may help determine if the funkiness is somewhere with the Sonos device setup, or with the Aqara device setup.

I had included a "fan off" when I was using IF statements and the fan would shut off, but not the music, regardless of what I did. I'm going to try what someone else suggested and right a non-Button Controller rule and see if that makes a difference.

-Thanks

I used the DoubeTapped button to shut off the switch and that worked. But I'd prefer to have the single "Pushed" button used to turn on and off the music. Still working on it!

:point_up:

There was an issue with the device itself. Under "In use by" it indicated it was in use by rules that no longer existed. I deleted the device and button controller rules, and now this works.

Thanks for your help with this folks!

1 Like

Something is wrong with that app; I would have suggested removing and re-creating.

However, what I was really asking for was action logs from running the rule (but it's normally helpful to enable all logging in Rules and Button Rules to make these clearer; your logs are a problem but would not have come from this). The document I linked to above shows an example of how to do this, and it a also been suggested nearly every time you have a similar question, yet it still appears to have never been done here.

Glad you got something figured out! Next time there is an issue, please enable and share all app logs as a starting point.

2 Likes