Author Topic: Gettings Responsed based on time of day.  (Read 237 times)

Uzaree

  • Newbie
  • *
  • Posts: 18
Gettings Responsed based on time of day.
« on: July 13, 2024, 01:02:41 PM »
********I modified this post so others can see what I wanted to do and how I accomplished it.*********

Original Post:
I want to have different responses based on the time of day.  I feel like I have the logic right in my head, but my syntax is incorrect.

I want to compare the time of day, either morning, afternoon or evening and depending on what time is was the response would be either Good Morning, Good Afternoon and Good Evening.

Can I use the {time} then have it compare another variable?  Thinking about it, the AM I could just test to see if the time has AM and I could do the AM logic.  I think the {TIMEAMPM} would work nicely there.  Then for afternoon and evening I would have to test the hole string.
****************************************


Solution:
This command is loaded anytime I load this profile.  I wanted two things when I wrote this, I wanted the response to seem more AI like by knowing what time of the say it was.  I only needed to know morning, afternoon and evening.  First, I tested against the system time and retrieved the {TIMEAMPM} token so I could easily tell what part of the day it was.  It would have been easier if we as humans didn't say afternoon and night, but we do so you have to account for that.  Then it was a matter of splitting the time for PM how I wanted to designate afternoon and night(evening).  Once I made my determination I setup the logic of 6pm using the {TIMEHOUR24} military time because it's just easier.  Once it goes through the logic tree it ends with a "How can I assist you."

A few notes:

Write 'Good Evening' to log :: Lines like this can be removed, I just used them to trouble shoot my code and to make sure I was getting what I thought I should be getting.

   Execute external plugin, 'MSCognitiveTextToSpeech - 1.0.7670.29377' using context 'Good Morning.' and wait for return  ::  This line is using the Microsoft Azure plugin to give me more realistic sounding voice. You have to setup and account in order to use it.  The first 500K characters are free per month.  So, to give that some perspective, the book "The Hobbit" is 95,000 words, if every word was 4-5 characters long that be close to 500K characters.  I can't see myself using that many characters with this, but I will have to keep an eye on it if go crazy with responses.

I used this youtube video to get that setup. https://www.youtube.com/watch?v=DvJ8FcthEO8

One other thing to make note of, the very first line is Stop VoiceAttack Listening.  This profile I call Jarvis, so from all my other profiles when I say "Jarvis" it loads this profile and turns listening off.  This profile I have a Prefix "Jarvis" that I have to say every time I use commands in this profile.  Then when I go back to the other profile Listening is turned back on.

Code: [Select]
Stop VoiceAttack listening
Set integer [Time_Of_Day] value to the converted value of {TIMEHOUR24}
Begin Text Compare : [{TIMEAMPM}] Equals 'AM'
    Execute external plugin, 'MSCognitiveTextToSpeech - 1.0.7670.29377' using context 'Good Morning.' and wait for return
   
Else If Text Compare : [{TIMEAMPM}] Equals 'PM'
    Begin Integer Compare : [Time_Of_Day] Is Less Than 18
        Execute external plugin, 'MSCognitiveTextToSpeech - 1.0.7670.29377' using context 'Good Afternoon.' and wait for return
        Write [Blue] 'Good Afternoon' to log
    Else If Integer Compare : [Time_Of_Day] Is Greater Than 18
        Execute external plugin, 'MSCognitiveTextToSpeech - 1.0.7670.29377' using context 'Good Evening.' and wait for return
         Write [Blue] 'Good Evening' to log
    End Condition
End Condition
Execute external plugin, 'MSCognitiveTextToSpeech - 1.0.7670.29377' using context 'How can I assist you.' and wait for return
« Last Edit: July 14, 2024, 09:10:18 AM by Uzaree »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Gettings Responsed based on time of day.
« Reply #1 on: July 13, 2024, 01:12:07 PM »
You could use "{TIMEHOUR24}" and check whether the value is greater than or equals the beginning of a given part of the day, and less than the beginning of the next part of the day.

Keep in mind that tokens are always text, so you'll need to set an integer variable to the value of the token to be able to perform the checks using normal condition actions.

Uzaree

  • Newbie
  • *
  • Posts: 18
Re: Gettings Responsed based on time of day.
« Reply #2 on: July 13, 2024, 01:36:43 PM »
i Just got it figured out and I was going to post the code for reference for anyone else.  Is that possible to do?
it dawned on me that with my logic chain, I was testing for AM/PM already, so I didn't have to do it anymore and I only needed the {TIMEHOUR24}

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Gettings Responsed based on time of day.
« Reply #3 on: July 14, 2024, 01:09:11 AM »
You can right-click the action list, choose "Copy All as Text" from the context menu, then paste here into a code block (click the # button)

Commands can also be exported (by exporting a profile and selecting only the specific commands you'd like to export).

Uzaree

  • Newbie
  • *
  • Posts: 18
Re: Gettings Responsed based on time of day.
« Reply #4 on: July 14, 2024, 08:44:32 AM »
Thank you Pfeil for your help!