Button Rules and Determining Which Button Was Pushed

I’m trying to learn, but what am I doing wrong?
I am trying to make 1 rule for 2 functions.
I have two switches “Dimmer A (button 1)” and “Dimmer A (button 2)”. I am trying to change the status of variable www.
When I press “Dimmer A (button 1)” variable www changes to true, but when I press “Dimmer A (button 2)” nothing happens.

Here are the two different rules I’ve tried - neither of them work.
If I make two separate rules everything works

Your rule is triggered by the action of the button 1 being pushed.
So when you do that, THEN $www is set to True.

There is no Else happening, the rule is triggered by the push of the button, nothing else has happened, so the ELSE part of your rule never runs.

I’m not sure what you want to achieve, so it’s difficult to propose a solution. But you can leave “Else” blank, add another if with the other button where you set $www to False.

You could also read up on context variables, because that’s what I believe would be perfect for this situation. But I’m afraid a bit difficult to jump in right away.

Thank you for taking the time to reply.
I tried to do as you suggested, making two rules. But that didn’t work either.
When I press “Dimmer A (button 1)” I can see that $www becomes briefly active and very quickly then becomes inactive.
Exactly the same thing happens when I press “Dimmer A (button 2)”, i.e. briefly active and then inactive.
My rule can be seen here.

Depending on how your source smart home platform implements buttons, you would likely want to use the event that triggered the rule as your condition rather than trying to query for the state of the button.

In other words, as soon as you push the button it emits a ‘pushed’ event, but when you query the status of the button just a moment later it’s either not actively in a pushed state or always retains the pushed state. In either case, the event is a better data source for building your rule as it tells you exactly which device and value triggered the rule.

Context Variables

You can use Context Variables to access information about the event that triggered the rule and use that in your conditions:

Triggering Device Name

If you want to combine multiple devices in a single rule and differentiate between which device triggered the rule, you would want to use:

  • Event → Device → Name

Triggering Device Value

If you have a single button in a rule and perhaps wanted to distinguish between a ‘pushed’ and ‘held’ event, assuming your device supports that, you would use:

  • Event → Device → Value

Value and Device Name

If you had a rule where you wanted to determine which button was activated and whether it was pressed or held, you could use both context variables in an if condition with AND.

  • $context.event.deviceName is ‘button 1’
  • $context.event.value is ‘pushed’`

Example: Which button was pushed?

Here’s an example showing how to distinguish if it was button 1 or button 2 pushed:

Edit: If you find it more intuitive, you could use a separate condition for each event that you are looking for. This approach would be required if you had more than 2 devices / trigger values in the Trigger as you wouldn’t be able to implicitly determine that the ‘else’ condition meant it was the other button.