EP SmartApp replacement for Shabbat-and-Holiday-Modes!

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                         
    return future.result()                                                                                   
  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()
1 Like

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.


@Ephrayim, but you can add a device label in-app? If that’s true, perhaps I’ll update it to work using that.

1 Like

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.

1 Like

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.

@ari, I’m working on a video tutorial for the aws setup. In the meantime, yes, by trigger I mean a ‘rule’. A usable cron argument could be 0 12 * * ? * (runs at 12 noon everyday).

1 Like

After much trial and error I have it working. Thank you again. This will definitely see more prevalent usage with detailed instructions or a video.

Just to confirm, for self hosting the cron only needs to run once per day and then it will take the proper action at shkia? Or should I set the cron to run more often?

Also, it would be useful if you could set an offset for prior to shkia, to allow the switch to turn on, say, 1 hour prior to shkia.

@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.

Ok thanks. In theory other Zmanim should be easy enough using the library. I may try to adjust to minchaketana or something and see how that goes

The video is finally here! It is at YouTube for anyone who may need it.

Is the elevation value in Self_Hosting.py in feet?

@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):

  1. Safe to assume that the switch turns on 18 mins before shkia, not at shkia?
  2. How do you actually use this in practice? Did you create a routine that watches the switch on Friday and runs a scene?
  3. 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?
  4. Another vote for a different end of Shabbat time - 42 mins.

Thank you.

FYI, IFTTT seems to be working now (at least on the app), if you want to use a Hebcal calendar and use the calendar to trigger a virtual switch.

1 Like

@jjgfromnj I assume the elevation value is in feet. However, I did not make the library that calculates the zmanim.

  1. The original program changed the switch at shkia, not candlelighting. I’ve since updated it to have an adjustable candlelighting offset.
  2. 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.
  3. 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.
  4. 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?

@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.

@Wajo357, alright, glad you got it working! It can be a bit difficult to set up, but that should be it. My setup has been working without any issues since it was installed!


We’ll find out on Friday! :wink:
Hopefully we don’t lose daylight savings time. Otherwise, I’ll have to go through this all over again! lol

1 Like