Hi,
Pretty new to all this and pretty overwhelmed TBH, just need some high level pointers to start off with (but feel free to throw some suggested code at me too!).
Pointing to the documentation is fine, but if you do so, could you point to the specific area(s) of it I should look at it please, rather than the whole lot, thanks! I have searached topics and see that maybe I can use states? to get schedule details, but beyond that, it’s a steep learnign curve.
So I have got a Shelly Button 1, with a simple URL link (placed via the App menu) to a Central Heating (CH) Shelly mini 3G relay, to turn it on (or off) based on a one or two button click, that works fine.
http://192.168.47.127/relay/0?turn=on or http://192.168.47.127/relay/0?turn=off
I have also got a script (function actually) made with a great deal of help from someone else, that turns on or off the 3 “ON” schedules of a Daily Set of 3# ON/OFF Windows (for the Central Heating). The function is on the Shelly that has the Schedules on it.
I added a link to this function as second URL of the Shelly Button 1 press and this also works fine, turning off the CH Schedule (so if I just turn off the relay it does not turn back on again 2 minutes later, using the schedule).
This is all done natively in the Shelly ecosystem.
What I would like to develop for HA integration, is a simple “If Then Else” logic, such that if I turn the schedule (only) back on, IF the current time lies WITHIN one of the three time windows, it turns the CH relay on; if not, then not. After that the schedule takes over as normal.
So I believe the logic is simply:
IF
Window1Start < “TIMENOW” < Window1End
OR
Window2Start < “TIMENOW” < Window2End
OR
Window3Start < “TIMENOW” < Window3End,
THEN
Turn CH Auto Relay = ON
OTHERWISE
No Action needed.
So, what I believe I need to do is this (but please correct me):
a. Mine the Schedule for the Start and End Times of the 3 Daily Time Windows and get the 6# Constants WindowXStartX and WindowXEnd, where X =1,2, and 3.
I believe http://192.168.47.127/rpc/Schedule.List provides the schedule (see output below) I assume I can get the time from this output for each pair of IDs, (ID3-ID5, ID6-ID8, ID9-ID12) but I am not sure which is the best mechanism for extracting the variables?
Should I use a Function (on the Shelly itself) or use a Script or a Template? Is there a Blueprint I can modify?
{"jobs":[{"id":2,"enable":false,"timespec":"0 30 6 * * 0,1,2,3,4,5,6","calls":[{"method":"switch.set","params":{"id":0,"on":true}}]},{"id":3,"enable":true,"timespec":"0 30 8 * * 0,1,2,3,4,5,6","calls":[{"method":"switch.set","params":{"id":0,"on":false}}]},{"id":5,"enable":false,"timespec":"0 0 12 * * 0,1,2,3,4,5,6","calls":[{"method":"switch.set","params":{"id":0,"on":true}}]},{"id":6,"enable":true,"timespec":"0 30 13 * * 0,1,2,3,4,5,6","calls":[{"method":"switch.set","params":{"id":0,"on":false}}]},{"id":8,"enable":false,"timespec":"0 30 15 * * 0,1,2,3,4,5,6","calls":[{"method":"switch.set","params":{"id":0,"on":true}}]},{"id":9,"enable":true,"timespec":"0 0 21 * * 0,1,2,3,4,5,6","calls":[{"method":"switch.set","params":{"id":0,"on":false}}]},{"id":12,"enable":true,"timespec":"0 0 0 * * 0,1,2,3,4,5,6","calls":[{"method":"Shelly.Update","params":{"stage":"stable"},"origin":"shelly_service"}]}],"rev":356}
I started looking at this example from the Shelly folks, but it’s pretty daunting.
b. Next, to run the IF-THEN-ELSE- statements, should I write this in a “Template” which evaluates the IF/Then logic above to True or False, If True then Turn the Relay On (and the Schedules). If not a Template then, what is the suggested mechanism please?
If anyone has some starting code examples or code library, I can play around with it, athat woudl be great.
Thank you!
k.