Just tried your suggestion and it threw an error and didn’t change the switch status. Here is the traceback.
/usr/NAS/Smartthings-Shabbos-Mode/Self_Hosting.py:48: DeprecationWarning: There is no current event loop
loop = asyncio.get_event_loop()
Traceback (most recent call last):
File "/usr/NAS/Smartthings-Shabbos-Mode/Self_Hosting.py", line 74, in <module>
File "/usr/NAS/Smartthings-Shabbos-Mode/Self_Hosting.py", line 49, in main
File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
File "/usr/NAS/Smartthings-Shabbos-Mode/Self_Hosting.py", line 38, in update_shabbos_switch
while devices[i].name.lower() != 'shabbos mode switch':
IndexError: list index out of range
@Ephrayim that error indicates that your simulated switch is not being detected by the program. Is it possible that it is not named ‘Shabbos Mode Switch’ (apostrophes excluded)? You can paste & run this code at the bottom of the program to spit out a list of all devices that can be detected:
async def test():
async with aiohttp.ClientSession() as session:
api = pysmartthings.SmartThings(session, token)
devices = await api.devices()
for i in range(len(devices)):
loop = asyncio.get_event_loop()
Thanks got it working! Looks like your program is using the device name rather than label. You are unable to modify the device name from the Smartthings app so perhaps you might consider using that instead especially since the ability to create virtual devices through the IDE will soon no longer be possible. Moreover, the virtual switch using the edge drivers runs locally unlike the simulated switch which runs in the cloud and creating the virtual switch in app you are unable to modify the device name.
When you rename a device in-app you are just rename the label not the actual device name which stays the same. Another thing to remember is that you can have multiple devices with the same device name but I think label needs to be unique.
First off thank you for your work on this. As a non programmer I am getting stuck at the Amazon EventBridge instructions. When you say create a trigger, is that a rule in amazon parlance? Could you assist with more detailed instructions for the programming challenged? Next could you provide a sample " valid cron() expression" we could use? Thanks again.
@JacobRosenfeld , the self-hosting cron should only run once per day. After it runs, the program will wait until shkia to change the switch. Therefore, the cron should be set to run slightly before the earliest shkia in your location (to minimize the amount of time it just sits there waiting).
I may try in the future to set it to change to shabbos mode at candlelighting.
@Rafael_M Thanks for doing this. I never got the old groovy trick to work, so I’ve basically set things using routines manually (and simple sunset offset routines).
I got the switch to respond using the test method you suggested. So now a few question (sorry if some are noobi):
Safe to assume that the switch turns on 18 mins before shkia, not at shkia?
How do you actually use this in practice? Did you create a routine that watches the switch on Friday and runs a scene?
How would you use this to differentiate between different chagim - for instance, I want the lights off later on Seder night than a typical Friday night. Or when there is a chag overlapping with Shabbat, or a 3 day yom tov?
Another vote for a different end of Shabbat time - 42 mins.
@jjgfromnj I assume the elevation value is in feet. However, I did not make the library that calculates the zmanim.
The original program changed the switch at shkia, not candlelighting. I’ve since updated it to have an adjustable candlelighting offset.
To use it in practice, personally, I have a routine that monitors the switch - constantly, not only on Fridays, as the whole point is to work even when yom tov is on a weekday - and then sets my location mode to ‘Shabbos’ when the switch is turned on and to ‘Home’ when it is turned off. I then have different scenes that run depending on what mode my home is in. I did it this way so it could seamlessly replace the function of shabbat-and-holiday-modes, which operated in such a manner. You can just set it to run scenes based on the switch directly, if you like.
Unfortunately, the program does not differentiate between different Yomim Tovim. If you want the lights off later on pesach that will have to be manually programmed. All the program does is turn the switch on at the beginning of the shabbos and/or yom tov, and turn it off at the end.
Vote received. Maybe eventually I’ll add in such a feature.
This is perhaps more of a linux question, but perhaps you know the answer - is there a way I can tell that the crontab job ran today? Does it write a file or something?
Also, I took your Self_Hosting.py and tried to make a file which was just “turn on” and another file which is just “turn_of”. After the def status, def update_shabbos_switch(mode), and def main sections, I just have main(‘on’) (or main(‘off’). When I run it (python turn_on.py) I get the following warning (but it works): py: 47: DeprecationWarning: There is no current event loop
loop = async.get_event_loop().
Any Idea how I can make this work without a warning?
Edit @Rafael_M , OK. I hope I got it! We’ll find out on Friday!
I’m not too savy with my pi, and ended up having to install the newer version of python, install some addition dependencies, change the python version on thonny to the latest version, learn how to set schedules… And much much more. I could have used my own YouTube video. Lol.