Increase/decrease ceiling fan speed by percentage


#1

1) Give a description of the problem
I need two pistons to control the rotational speed of my ceiling fan. The two pistons are:

  1. Use existing fan speed and increase it by 10%
  2. Use existing fan speed and decrease it by 10%

2) What is the expected behaviour?
When piston #1 is fired the ceiling fan will increase fan speed by 10%
When piston #2 is fired the ceiling fan will decrease fan speed by 10%

3) What is happening/not happening?
I’m not sure where to begin, so don’t have any piston code written yet


#2

First thing we’ll probably need to know is does the fan report its current speed, can it be queried or it is guessing based on what speed setting you initially sent through webcore?


#3

So I spent some time working on a piston, and got one working but the other is not.

The piston that does work is exactly the same as the screenshot, except on line 26 where I use a “+” to increase the fan speed by 14 points. I can manually run the piston (or via an Apple shortcut) and the fan speed always increases by 14 points.

What is not working is the piston that does the same thing, but decreases the fan speed by 14 points. When I run this piston nothing happens. Zero change in fan speed.

However, when I’m in the task editor and edit the ‘minus’ expression it does evaluate to the current value minus 14. So I’m not sure why the fan isn’t getting the command to set the speed to the lower value.


#4

What about a bare test piston that just decreases the fan speed from a known level? Does it work?


#5

2021-12-09_14-33-28

Yes, running this bare piston does change the fan level.


#6

Humor me and try adding a wait for 10 secs before sending the fan speed on line 26.


#8

Waiting didn’t help. Any other ideas?


#9

So I got it working…fiddled around with the logic a bit and increased the decrement value to 25. I created an Apple shortcut on my Mac calling the Webcore URL and it works great. Now I can assign the shortcut to a streamdeck key.


#10

One small observation about piston “dn27t”…

  • {_FanSpeed} is hard coded up top
    (this is set the moment the piston begins)
  • Then, a refresh is sent
  • Finally, set level occurs based on the original variable

I suspect “refresh” does not do what you want… but even if it does, it will never update the variable on line 17…

If you think refresh is required, I would try this modified structure:

define
    integer FanSpeed = (no value set)  <-- Intentionally left blank
end define

execute
    with Switch 4
        do Refresh
        Wait X seconds
        Set variable FanSpeed = Switch 4's fanLevel
        setFanLevel (FanSpeed - 25)
    END WITH
END EXECUTE

The WAIT duration may need to be fiddled with. I have seen new data taking anywhere from 1-61 seconds to return. (with some devices never refreshing manually) Ideally, you should wait a few seconds more than your longest return.


#11

Why not just set the variable with the change at the beginning of the piston?