Turn lights on with a scene switch


#1

1) Give a description of the problem
Need help setting up my first piston.

2) What is the expected behavior?
I wish to have a piston that does the following.

I have a smart dimming switch on one side of the master, and a scene button near my nightstand.
I want to hit the button on the nightstand and have it action the dimmer switch.

So:

when button pressed, check status of the dimmer,

if off turn on to 50%

If more than 1% turn off the dimmer.

3) What is happening/not happening?
Not sure how to build it.

Afterwards I wish use this example to build a similar scene when the button is HELD.


#2

Try this…


#3

This worked perfectly. Thank you for the help.

This will give me a model to build my other automations.


#4

Hello, Looking for some advice.

Here is the Piston I setup:

It seems that about 40% of the time the light turns on and then immediately turns off. Or sometimes it stays on for 40 seconds or so and then shuts off.

Is there any way to make it more robust? Or have I made a mistake?


#5

Enable full logging and post it so we can see or try to see where it’s failing.


#6

Thanks for the advice, I’ve done that.


#7

I would suggest that when the button is pushed, the conditions become true.
As soon as the dimmer turns on, the conditions become false, therefore your Light will turn off almost immediately.
What are you actually trying to achieve.
EDIT:You can just use Turn Off BTW. You don’t need to use set switch to off.


#8

Here are two logs of the situation happening.

+2ms ╔Received event [Hank Scene Controller].button = pushed with a delay of 72ms
+192ms ║RunTime Analysis CS > 19ms > PS > 103ms > PE > 69ms > CE
+195ms ║Runtime (37662 bytes) successfully initialized in 103ms (v0.3.105.20180628) (192ms)
+196ms ║╔Execution stage started
+207ms ║║Comparison (enum) pushed gets (string) pushed = true (1ms)
+209ms ║║Condition #6 evaluated true (6ms)
+220ms ║║Comparison (enum) off is (string) off = true (2ms)
+222ms ║║Cancelling condition #7’s schedules…
+223ms ║║Condition #7 evaluated true (12ms)
+224ms ║║Cancelling condition #1’s schedules…
+225ms ║║Condition group #1 evaluated true (state changed) (23ms)
+228ms ║║Cancelling statement #4’s schedules…
+270ms ║║Executed physical command [Master Bath Dimmer].setLevel([50]) (38ms)
+271ms ║║Executed [Master Bath Dimmer].setLevel (39ms)
+274ms ║╚Execution stage complete. (78ms)
+276ms ╚Event processed successfully (276ms)
+2ms ╔Received event [Hank Scene Controller].button = pushed with a delay of 176ms
+241ms ║RunTime Analysis CS > 30ms > PS > 127ms > PE > 83ms > CE
+244ms ║Runtime (37659 bytes) successfully initialized in 127ms (v0.3.105.20180628) (240ms)
+245ms ║╔Execution stage started
+256ms ║║Comparison (enum) pushed gets (string) pushed = true (1ms)
+258ms ║║Condition #6 evaluated true (7ms)
+268ms ║║Comparison (enum) on is (string) off = false (2ms)
+270ms ║║Cancelling condition #7’s schedules…
+271ms ║║Condition #7 evaluated false (11ms)
+272ms ║║Cancelling condition #1’s schedules…
+273ms ║║Condition group #1 evaluated false (state changed) (21ms)
+276ms ║║Cancelling statement #2’s schedules…
+315ms ║║Executed physical command [Master Bath Dimmer].off() (18ms)
+316ms ║║Executed virtual command [Master Bath Dimmer].setSwitch (31ms)
+319ms ║╚Execution stage complete. (75ms)

@bobbles
The goal is:
I have a smart dimming switch on one side of the master, and a scene button near my nightstand.
I want to hit the button on the nightstand and have it action the dimmer switch.

So:

when button pressed, check status of the dimmer,
if off turn on to 50%
If more than 1% turn off the dimmer.


#9

Isn’t that what it is doing.
Turning on then off again straight away.
Seems a bit strange. Dont you want a delay before it turns off.


#10

@bobbles

Those are separate button clicks.

On each button click I want it to see if the light is already on. If it is on(more than 1%) turn it off.
Click the button, if the lights are off, turn them on to 50%


#11

If thats the case I would try the following.
Break it out into 2 IF’s

IF
Button pushed
AND
Dimmer Off
THEN
WITH
Dimmer
DO
Set level to 50%

IF
Button pushed
AND
Dimmer On
THEN
WITH
Dimmer
DO
Turn Off

Is this what you are after?


#12

@esteidinger. Did any of the suggestions above work for you or haven’t you had time to try anything yet?


#13

Thank you @bobbles I haven’t had time to implement the change.

I would be happy to try this Piston, the old piston worked great 80% of the time. So I’m assuming my problem is in the logic.


#14

@bobbles Unfortunately your suggestion did not work.
100% of the time when I hit the scene switch the light would turn on to 50% and then turn off.

I have reverted to the original suggestion for now.


#15

Hmm. Very strange. Wonder why it turns off straight way.
How about putting a wait 15 seconds after the turn on in the first if. If this works you can gradually bring the wait down if you wish.
It could be that the second IF is seeing the first IFs push when the light turns on.


#16

In the two log files you posted, what is the timestamp on each of the triggers? I’m curious if your switch is occasionally reporting two rapid-fire button pushes, so the second time thru it executes the “else” section.


#17

In the provided logs they were a few button presses apart. I hit the button a number of times while standing in the room and only pulled out the ones that “failed”


#18

I put in a 15 second wait. Now the light turns on for 15 seconds and then turns off.


#19

The two logs you posted - one time the lights turn on (50%) and in the second they switched off because the lights were already on. In other words, the piston behaved/sent the commands the way you wanted it to. Did you see something else with the actual lights?

A 15 second wait schedules a wake-up for the piston 15 seconds in the future. When the piston wakes up 15 seconds later and evaluates “did button one get pushed”… that is no longer true so it will execute the “ELSE” part of your condition and switch the lights off.

There are a few ways to write the piston you are trying to do, but there’s absolutely nothing wrong with the logic in your and it should work as you want it to. I’m wondering if there is some occasional failed communication to your devices… but to figure that out we’d need to look at the complete logs, including timestamps, and see if the results in the log match what you’re seeing with the lights.


#20

In both situations the lights turned on for 1 second, and then off.

Ok, I will re-enable the first piston and then test it and get you a series of logs. I’m afraid there will be a number of perfectly OK events in between. I’ll figure out a way to capture it all correctly.