Alarm Clock Plugin

Posted on
Sat Nov 23, 2019 10:05 am
hamw offline
Posts: 1214
Joined: Mar 31, 2008

Re: Alarm Clock Plugin

Was wondering if you could include a device state that shows only the HH:MM, not full date time? I am trying to use the device state in a variable and can only get the full date time. I tried to directly insert the current set time as HH:MM into a variable using the Indigo menus but that option is not available, so I set up below:

Code: Select all
dev = indigo.devices[1596829398] #radio alarm clock
time = (dev.states["startTime"])

indigo.variable.updateValue(1352903259, str(time))


but it puts in the full date time string.

thanks!

Posted on
Sun Nov 24, 2019 8:38 am
DaveL17 offline
User avatar
Posts: 5900
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Alarm Clock Plugin

Your script leads me to believe that the timestamp is being stored as a string in the source dev state. If that's the case, you can grab what you want by using an index. (I would also avoid using the variable name 'time' as that's a reserved word in Python). Try this:
Code: Select all
dev = indigo.devices[1596829398] #radio alarm clock
t = (dev.states["startTime"])

indigo.variable.updateValue(1352903259, str(t[11:16]))

Should be pretty close.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Mar 15, 2020 8:47 pm
hamw offline
Posts: 1214
Joined: Mar 31, 2008

Re: Alarm Clock Plugin

Thanks very much, that worked. Sorry to ask this question in the Alarm Clock Plugin forum, but since it is an extension of the prior post, hope you will not mind.... :-)

Tried to use this in a similar way for my thermostat control page readout. The initial AS is here:


Code: Select all
using terms from application "IndigoServer"
tell application "IndigoServer"
       set HomeReadout to value of variable "Home" as string
       set value of variable "HomeReadout" to (characters 17 through -1 of HomeReadout) as text
    end tell
end using terms from


and what I adapted from your snippet is here:

Code: Select all
HomeReadout = indigo.variables[306104832].value #HomeReadout

Home = indigo.variables[1596654921].value #Home

indigo.variable.updateValue(HomeReadout, str(Home[17:-1]))


Seems like it should be so simple, but it keeps throwing errors? I've tried changing "indigo.variables" to indigo.variable" etc without success, as well as deleting the .value and then substituting .str. Here are some errors. The first is with naming indigo.variable to indigo.variables:

Code: Select all
  Script Error                    embedded script: No module named variable_watcher
   Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 1, at top level
ImportError: No module named variable_watcher


Code: Select all
   Script Error                    embedded script: invalid syntax
   Script Error                    around line 31 - "pass"


My guess is that since it is text it is not a value?

Posted on
Mon Mar 16, 2020 1:14 am
howartp offline
Posts: 4258
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Alarm Clock Plugin

HomeReadout = indigo.variables[306104832].value #HomeReadout

Home = indigo.variables[1596654921].value #Home

indigo.variable.updateValue(HomeReadout, str(Home[17:-1]))


Change last line to

Code: Select all
 indigo.variable.updateValue(306104832, str(Home[17:-1]))


You’re trying to update a variable called whatever the value of HomeReadout is, rather than the ID or name of that variable.

Posted on
Tue Mar 17, 2020 4:21 pm
hamw offline
Posts: 1214
Joined: Mar 31, 2008

Re: Alarm Clock Plugin

Thank you, I see the error. Much appreciated!!!

Posted on
Tue Mar 16, 2021 2:58 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Alarm Clock Plugin

Just now got around to tinkering with this plugin... I've got a couple questions and an error.
"Wednesday" won't toggle from "false" -> "true". When I use the toggle Wednesday command from a CP, I get this in the log... (All the other days are toggling just fine)
Code: Select all
EPS - Alarm Clock Error         Error in plugin execution ExecuteAction:

Traceback (most recent call last):
  File "plugin.py", line 114, in deviceActions
KeyError: key not found in database


Primarily I plan to use this plugin to replace some schedules that I like to adjust on the fly (from a control page).... like my evening thermostat setting, or monitoring the kids tvs, in addition to standard use as an alarm clock.... so the question is,
Is a "Toggle device" a required item? Can alarm default duration be 0 and still activate the "Alarm on action"
If alarm duration is 0, will the Alarm on and off action run at the same time, neither or just the on?

Sidenote: On Devices.xml, there are two "startTime" Line 185 & line 213

Bill
My Plugin: My People

Posted on
Tue Mar 16, 2021 4:40 pm
hamw offline
Posts: 1214
Joined: Mar 31, 2008

Re: Alarm Clock Plugin

I don't think you can turn off all days. It's not just Wednesday, it's the last one you try to turn off.

Posted on
Tue Mar 16, 2021 7:41 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Alarm Clock Plugin

hamw wrote:
I don't think you can turn off all days. It's not just Wednesday, it's the last one you try to turn off.


That's a different error...
Code: Select all
EPS - Alarm Clock Error         Control page attempted to turn off every day of the week, this isn't possible.  It's easier to just turn off the alarm!


I'm trying to toggle "Wednesday" to "on" (true). ....

Some more testing... I created another alarm clock, identical in design and this one has a working "Wednesday". It looks like when the first device was created, the device state didn't save right giving it a "key not found" error.... but I can't re-create it and I don't know if there is a way to fix it (outside of just recreating the alarm clock device).

forgive the ugliness of the testing control page... in the below examples.... "Temp Change" is the nightly drop of the AC set point." I will create another alarm device for the morning version that raises the AC set point. The 2nd one is for a light in the fishtank. The on time can fluctuate, but it should stay on for about 8 hours. So Alarm On action will turn the light on. 8 hours later (480 minutes) Alarm Off action will turn the light off.

For my use, I still have some tinkering to do... like add another set of up/down arrows to manipulate the AC set point that it's going to change to (basically modifying the "On" action from the same page).

Python ?: I'm also trying to figure out a way to change duration by endTime. Use a HH:MM saved as a variable or something, untested and can guarantee won't work because my python time math sucks....
Code: Select all
from datetime import datetime
alarmClock = indigo.devices[402185762]
newTime = "05:30" # replace later with a variable or something
oldDelta = alarmClock.durationMinutes
newDelta = newTime - alarmClock.startTime  # will need to convert newTime to a datetime object
diference = newDelta - oldDelta
   if diference > 0:  # add time to duration

      pluginId = "com.eps.indigoplugin.alarm-clock"
      alarmClockPlugin = indigo.server.getPlugin(pluginId)
      if alarmClockPlugin.isEnabled():
         alarmClockPlugin.executeAction("increaseDuration", deviceId=402185762, props={'stepIncrement':diference})
   
   else: # difference is a negative number, so subtract from current duration
      pluginId = "com.eps.indigoplugin.alarm-clock"
      alarmClockPlugin = indigo.server.getPlugin(pluginId)
      if alarmClockPlugin.isEnabled():
         alarmClockPlugin.executeAction("decreaseDuration", deviceId=402185762, props={'stepIncrement':diference})   
Attachments
Screen Shot 2021-03-16 at 7.33.11 PM.png
Screen Shot 2021-03-16 at 7.33.11 PM.png (93.15 KiB) Viewed 894 times

Bill
My Plugin: My People

Who is online

Users browsing this forum: No registered users and 0 guests