Announcement

Collapse

Contacting HomeSeer This Week

HomeSeer is open and operational this week. All orders are being processed and shipped as usual. However, some staff are working from home. If you need to contact HomeSeer for support or customer service, please use our Email or Chat options. https://homeseer.com/contact-us/
See more
See less

Virtual device as time when one event should trigger (dynamic alarm time)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Virtual device as time when one event should trigger (dynamic alarm time)

    Hi,
    I would like my phone to send time and date every night when is next alarm going to happen, f.eks. phone would at 03:00 use tasker to check if and when is next alarm set, and send this info to homeseer like nextAlarm=07:45 21.11.2019 (or in whatever format works best).

    Then homeseer would 15min before this time turn on the lights, 10mins before it would reise the shades, and 2min start some music via plex or whatever.

    The only solution that comes to my mind is to have a rule running every minute and check if now is the right time to run by comparing current time with virtual "nextAlarm" device.

    But perhaps there is some much easier and less "log spamming" solution?
    Can we somehow set event time dynamically, so that event engine would basically do this check for us?

  • #2
    For events that trigger at specific times, yes, it is possible to change their trigger time dynamically through a script. I do very similar things as you when we change the alarms on our Squeezebox radios. I can’t help with the tasker part, but can help with the HS script side.
    HS 3.0.0.548: 1990 Devices 1172 Events
    Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

    Comment


    • #3
      Hi.

      I have just made the exact same.

      I made a virtuel device that gets it's 'time' set via Tasker. (Json call) The value is passed as a decimal value and as a text to the device.

      Click image for larger version

Name:	Clipboard.png
Views:	140
Size:	9.4 KB
ID:	1341420

      I then made a script that get's triggered whenever the virtuel device get's it's value changed.

      That script sets an alarmtime i my Sonos and sets the starttime for another event used to dim the lights up.

      Code:
      Public Sub Main(parm As Object)
              Dim PerAlarm As String = hs.DeviceValue(420)
              PerAlarm = hs.DeviceString(420)
      
              If PerAlarm = "Off" Then
                  'Slå Sonos alarm fra
      
                  hs.RunScriptFunc("sonos.vb", "Main", "Sovevaerelse||D" & "", 0, 1)
                  ' Slå automatisk lys fra
                  hs.DisableEvent("TændLys")
      
              Else
                  Dim AlarmTime As Date = PerAlarm
                  AlarmTime = AlarmTime.Subtract(New TimeSpan(0, 1, 0))
                  Dim SonosAlarm As String = AlarmTime.ToString("HH:mm")
                  hs.RunScriptFunc("sonos.vb", "Main", "Sovevaerelse|" & SonosAlarm & "|E" & "", 0, 1)
                  AlarmTime = AlarmTime.Subtract(New TimeSpan(0, 4, 0))
                  hs.EnableEvent("TændLys")
                  Dim RefVal As Integer = hs.GetEventRefByName("TændLys")
                  Dim res As Boolean = hs.EventSetTimeTrigger(RefVal, AlarmTime)
                  hs.SaveEventsDevices()
      
              End If
          End Sub




      Comment


      • #4
        Thanks, I am still learning homeseer and still didn't write any script, but this is exactly what I need.
        Here I would then set few events based on user preferences, thank you!
        Btw PerBau would you mind sharing the tasker part as well? I am most interesting in formatting the date and time, as I think I have retporting time figured out from a few years before when I was still on domoticz.

        Comment


        • #5
          This task is called whenever the Alarmapp is started and also every 1/2 hour and only if my phone is on my local wifi.

          It checks if there is an alarm and if there is less than 24 hours until it starts.

          And this uses AutoAlarm in Tasker.

          Code:
              A1: AutoAlarm [ Configuration:NOTE: This will not work correctly if the 'Relible Alarms' option is enabled in Tasker. No extra configuration needed Timeout (Seconds):52 ]
              A2: If [ %year ~R [0-9]+ & %daysc eq 0 ]
              A3: HTTP Request [  Method:GET URL:http://192.168.1.253:8080/JSON?reque...ue=%taskertime
              A4: Variable Search Replace [ Variable:%taskertime Search:: Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In Array: Replace Matches:On Replace With:, ]
              A5: Flash [ Text:%hour. %minute %taskertime Long:Off ]
              A6: HTTP Request [  Method:GET URL:http://192.168.1.253:8080/JSON?reque...ue=%taskertime
              A7: Else
              A8: HTTP Request [  Method:GET URL:http://192.168.1.253:8080/JSON?reque...ring&value=Off
              A9: HTTP Request [  Method:GET URL:http://192.168.1.253:8080/JSON?reque...ue&value=00,00
          PS: Are you aware off https://www.hjemmeautomasjon.no/ ?

          Comment


          • #6
            I am doing something similiar with Tasker and Homeseer for my morning alarm.

            Just a suggestion, which when I implemented improved my methodology. I store time on both Homeseer and Tasker as a integer minute count, the number of minutes into the day. In other words, 6:00am would be minute 360, 5:30pm would be minute 1050 (17*60+30). Doing it this way means I do not have to worry about am or pm, or the fact that Homeseer and Tasker (Android) store time differently, and comparison of time is simpler as well. And its quite simple to convert back to HH:MM format on both sides (Hour = Minutecount DIV 60 [integer divide], Minute = Minutecount MOD 60).

            Comment


            • #7
              I use a string from a virtual devices to set start and end times for running a crock pot. In my case I'm setting the times in HS Touch.

              Code:
              Sub Main (ParmTemp As Object)
              
                setEvent(hs.GetDeviceRefByName("Crock Pot Start Time"), hs.GetEventRefByName("Crock Pot On"))
              
                setEvent(hs.GetDeviceRefByName("Crock Pot End Time"), hs.GetEventRefByName("Crock Pot Off"))
              
                hs.writelog("Note", "Set Start and End Times for Crockpot")
              
              End Sub
              
              
              Sub setEvent(DeviceRef, EventRef)
              
                Dim StartTime = hs.DeviceString(DeviceRef)
              
                Dim Parms As String() = Split(StartTime,":")
              
                Dim hour = Parms(0)
                Dim minutes = Parms(1)
              
                Dim d as Date = new DateTime(1, 1, 1, hour,minutes, "00")
              
                Dim res As Boolean = hs.EventSetTimeTrigger(EventRef, d)
                hs.SaveEventsDevices()
              
              End Sub
              Karl S
              HS3Pro on Windows 10
              96 Devices
              54 Z-Wave Nodes
              37 Events
              HSTouch Clients: 3 Android, 1 iOS
              Google Home: 3 Mini units

              Comment


              • #8
                Thanks guys, very usefull answers, I will test it soon

                Comment


                • #9
                  hi guys, could use your help a bit more ( sparkman you offered? ). Finally got everything set up in order to continue with this, now I got so far to the point where I have total minutes to the next alarm set in one virtual device. Its string is now 1927.98 which means there is like 34 hours to the next alarm.
                  I will check for next alarm and overwrite this value, so I was thinking to somehow set up delayed task when this virtual switch change? Could that be a way to go?
                  I would first cancel the timer, and set the timer to the event in f.eks. 95 minutes, is that possible?
                  Any tips on how to proceed and what to check? Still didn't got around to making a script, so apologies if I ask something very obvious. (I have a lot of ambition, and not enough time )

                  Comment


                  • #10
                    Actually, I've got this far, and this works as expected
                    Sub Main (Byval parms as object)
                    hs.DebugMode = 131

                    Dim d as Date = DateTime.Now.AddMinutes(10)
                    Dim EvRef As Integer = hs.GetEventRefByName("Wake up scene")
                    Dim res As Boolean = hs.EventSetTimeTrigger(EvRef, d)
                    hs.SaveEventsDevices()

                    End Sub
                    But when I try to add the time dynamically, this script goes into the endless loop. I will play more tomorrow, if you guys have any suggestions please let me know

                    Sub Main (Byval parms as object)
                    hs.DebugMode = 131

                    Dim minutesToAlarm
                    minutesToAlarm=Math.Round(hs.DeviceString(310))

                    If minutesToAlarm < 1440 Then
                    Dim d as Date = DateTime.Now.AddMinutes(10)
                    Dim EvRef As Integer = hs.GetEventRefByName("Wake up scene")
                    Dim res As Boolean = hs.EventSetTimeTrigger(EvRef, d)
                    hs.SaveEventsDevices()
                    End If

                    End Sub

                    Comment


                    • #11
                      Originally posted by dakipro View Post
                      hi guys, could use your help a bit more ( sparkman you offered? ).
                      dakipro Sorry, missed your post. Let me know if you still need help. Did you get your unintended loop sorted out?
                      HS 3.0.0.548: 1990 Devices 1172 Events
                      Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                      Comment

                      Working...
                      X