Help with lighting piston idea


#1

1) Give a description of the problem

I want to set up some lights that will remind me when certain tasks need to be done. My idea is this:

Light bulb comes on in specified color when task is due to be done again.

After doing the task, I execute the piston.

Piston will turn off the light bulb until a certain number of days pass, then turn on at 4 am the next day it’s due.

If the piston hasn’t been run again, thus the task is overdue after 24 hours, then start to blink the light (I chose to flash between 100% and 20% 10 seconds each) and try to do the flashing for 24 hours.

If still not done, start flashing in some more attention getting pattern and continue that for quite a while.

2) What is the expected behaviour?

See above.

3) What is happening/not happening?

I executed the piston. The light went on at 4 am the next morning. It stayed on for presumably 24 hours, but the following morning it was off, and not flashing. I don’t know if there’s a better way to do what I’m doing. Or even if it’s something that can be done in Webcore. Any ideas or tips or reasons why it never blinked would be appreciated.

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full
I didn’t have full logging turned on yet.


#2

You have several things happening in one piston. I think I have the general idea of what you are trying to do. These tasks can be handled with webcore. But I do have a couple of questions.

How do you know when the task needs to be done again?

Do you have a specific number of days before the light needs to be turned on?


#3

I would be configuring a different piston for each task. So the timing would depend on the task. For the first task that I’m concentrating on, it’s something I want to do every day (scoop the cat litter). So I’m envisioning that I can use a Flic button to execute the piston (I have a Flic hub.) so I scoop the litter, then press the button. The piston will execute and shut off the bulb. Then turn it back on at 4 am so it will remind me to do it the next day.

The flashing is to make it visually obvious to my forgetful brain that it’s been too long since I did the task.

Other tasks I have in mind (which would be separate bulbs) might be less frequent than daily.

Does that help?

I’m wondering if I can dynamically calculate a time and date for the next time the bulb should come on and set it to wait until then?


#4

Got it. I’m not at home right now but I will throw together some pseudo-code for you to look over.

Yes, these should help. https://wiki.webcore.co/Functions#addDays


#5

Your math looks right… 4320 times 20 seconds equals 24 hours…

Personally, I have never tried flashing for longer than one minute… and to be honest, in my household, I would never want a piston executing almost 9 thousand times a day…


Would you be happy with the bulb changing to two different colors?
(one color for the early alert, and one color for the late alert)

If your answer is “Yes”, I have a good idea in my head.


#6

Hmm, well, the problem with changing color is that I got a floor lamp with five heads and my plan was to assign a different color to each bulb. So adding additional colors seems like it would be either too confusing or not attention-catching enough.

I hear you on the number of operations, though. :face_with_monocle: Any way to tie in a motion sensor so it would only flash when it detected motion? I don’t know how you’d tie that to a dynamic time frame, though.


#7

Here is how I would do it:

First, create a Simulated Switch in the IDE (lets call it “Litter”)

Then create a piston something like this:

Every day at 4AM
    Turn on SimSwitchLitter
END EVERY

Every day at (bedtime?)       \
    Turn off SimSwitchLitter   (Optional block)
END EVERY                     /

IF Sensor's motion changes to active
Then
    IF SimSwitchLitter is on
    Then
        Flash lights for 1 minute
    ELSE
        Do normal Motion Sensor commands here
    END IF
END IF

The second block here is optional, and should only be used if you do not want to be disturbed late at night…


The only manual requirement is:
Once you clean the litter pan, you should turn off the SimSwitch, and you will not get any more reminders for that day. (“Alexa, turn off Litter” works great for hands-free)

The method above is for daily reminders, but it can be beefed up for every two days etc if you want.

The beauty of this is the light will only flash when you (or the cat) walk past the motion sensor… So there will be no WAITs, LOOPS, or crazy network chatter…


#8

I know this is completely different then what you are using but might think about it. For visual indicators i use a cheap fire tablet and action tiles then create some virtual switches and you can either mount the tablet where it will be easy to see or set it on a counter somewhere. The tiles can be set to different colors when on/off set to spin, pulse, etc. Plus you can tap the tile to turn it back off when you completed your task. I use this on many different pistons. washer/dyer alerts, turn on/off lights unlock/lock doors, etc.


#9

I’ve thought about that. But I’m not sure I have anywhere good in my house to put a tablet where it could be connected to power.


#10

For making custom mounts, I highly recommend the moldable glue called “Sugru”.
Feels and shapes like silly putty, but firms up within 24 hours… Yet still remains flexible.

It is quite inexpensive, and does not require drilling any holes in your walls or cabinets…

Here is an example of a tablet mount in use:


#11

Very good idea. My wife uses that. Never thought to use it on my tablet. I found a mount on amazon for it. Uses 3M tape strips which can be removed from the wall without damage. Very good to cause I’ve moved it twice now. Then I found this mount


#12

I actually found a place that sells mounts for the fire tablets and what i did was remove 2 switches from my wall and replaced them with this mount. I then put 2 smart light bulbs in the fixtures that the switches controlled. You can buy the mount with a 110 VAC to 5 VDC converter that mounts into the space where the switches were that will power the tablet. Make sure to order the 120/240v AC power option if you decide to order it. When finished it looks like it was always there. No wires showing anywhere. Then I added those 2 blubs as action tiles and now I can control them with the tablet as well as all my other smart switches, plugs, etc On the tablet I use a app called Fully Kiosk Browser. Its perfect for this type of use as it can turn the screen on the tablet off when not in use and turn it back on again when the camera on the tablet see’s motion.


#13

Yeah, not really interested in buying a tablet or finding a place to mount it or doing any electric work in the crappy old small boxes in our house right now.

Back to piston programming…

I’m rethinking my idea as two pistons. One of which would be manually triggered when I complete the task. It would turn off the light and set a global date time variable with the current day and time to record when the task was last done.

Second piston would trigger off a motion sensor and control the bulb based on time since the global variable. But I could use some help working out an expression for date math.

I think using a switch case would be nice, if I can work out one expression that would let me set the ranges I want. But it’s not as simple as number of hours. I think basically I want number of calendar days. So if I do the task today, no matter what time, tomorrow would count as one day, no matter what time.

Any ideas on that?


#14

How about something along these lines. This one is set to 30 seconds because I used it to not turn off a light when I open then close the door behind me then when I exit the same door later it will turn off the light in the room. I believe it could be modified to fit your needs as you can change the time from seconds to minutes, Hours, Days, Weeks.


#15

I don’t want to just add hours or days, that’s the problem. No matter whether I do the task at 10 am or 10 pm in a given day, I want it to be considered “needing to be done” the next morning.


#16

This is what i had in mind when i suggested you make use of the timed restriction. This is set to 4 days but can be changed to whatever you want. Switch 10 is a virtual switch which you can turn on.

This will do exactly what you said you wanted to do.

After doing the task, I execute the piston.

Piston will turn off the light bulb until a certain number of days pass, then turn on at 4 am the next day it’s due.

If the piston hasn’t been run again, thus the task is overdue after 24 hours, then start to blink the light (I chose to flash between 100% and 20% 10 seconds each) and try to do the flashing for 24 hours.

If still not done, start flashing in some more attention getting pattern and continue that for quite a while.


#17

For this portion of your goal, I would use a formula to determine what day of year you did the task on. Then, in any future execution, you can compare the current day of year with the original.


Here is the expression to find out the Day Of Year:
formatDateTime($now, 'D')

as seen here:

pic


#18

Pro Tip:

The day the task is completed, if you store the Day of Year in {taskDoY}, and each subsequent run, you update the current Day of Year in {currentDoY}, then you can always do math based on:

{currentDoY} minus {taskDoY} equals how many days have passed

Well, sorry. Not always. About 99% of the time:

You can account for the first & last days of the year by adding a simple IF condition:

IF {currentDoY} is less than {taskDoY}
Then
    Set variable {taskDoY} = {taskDoY} - 365
END IF

For example, if the event happened on Dec 30 (taskDoY=364), but today is Jan 1 (currentDoY=1), then 1 is less than 364, so change {taskDoY} to 364 - 365 = neg 1

This way, you can consistently use:
{currentDoY} minus {taskDoY}
to determine how may calendar days have passed.
(in this example, 1 minus neg 1 = 2)

The rest of the year, that single block will not execute, but it is a safety net for the very end/beginning of the year.