[RELEASE] Google Calendar, Task, and Gmail Search and Gmail Notification Device

Thank you for this great app. I would like to use it to trigger 3 states: morning, evening and/or both. The source is an email I receive from my electricity company asking me to move my electricity consumption. I tried to look through all the messages to see if anyone had done something similar but without success The email received may contains up to two request periods: morning, evening and/or both. Could you put me on a path to know how in my research I can find the conditions to then take related actions. The included text may look like this when two events occur on the same day:

February 23, from 6 a.m. to 9 a.m., morning.
February 23, from 4 p.m. to 8 p.m.

Thanks in advance

@Curiosity I am unclear on what you are trying to accomplish. Are you trying to parse the time frames from the content of the email and then schedule the switch based on those times? If yes unfortunately that is not possible with this app. You can parse text from Google items and store them in variables but turning that into a schedule is unfortunately more advanced that this app can currently do.

Simpler than that, with two virtual switches: one for day's event and another for the evening's event. If 6:00 a.m. to 9:00 a.m. is read, the day switch will be switched, if 4:00 p.m. to 9:00 p.m. is read, the evening switch will be triggered. Finally, if as in my previous post both periods are present in the email, both switches will be triggered.

I'm able to search emails for a single result. My challenge is if in a single email it can come to several results depending what's in it as in my need.

If the only way to do it is to make 3 searches on 3 differents time, I'll do it like that.

I would recommend you open Gmail in your browser to test various queries to find the match you are looking for. You can use these helpful sites to come up with your query:
https://www.googleguide.com/minus_operator.html

Within one search you can use and/or and the minus sign to exclude certain phrases. Once you get the results within Gmail you are looking for you can utilize that within the search trigger.

Would it be possible to let this app flip an existing switch rather than just a child switch ? I have an existing switch that I want to switch and now I have to instead get the app to run a rule that will flip the switch.

In the child switch section of the search trigger you can control other switches in todays version. It will toggle the child switch along with the selected devices.

Given this is based on an ST version it started with controlling a child switch only and I have slowly added the Additional Action features to perform other actions since it doesn’t always make sense to have a child switch especially with notifications. Creating the child switch is optional as well. I suppose I could add switch control to the additional actions section and remove it from the child switch section.

Creating the child switch does not seem optional to me, we must specify a name. It doesn’t make sense to create a child switch, I already have one.

Currently in order to toggle additional switches it is required to also create a child. But overall it is optional with that toggle in your screenshot.

Know you’ve been using this app for a while and know this was based on a port of a ST app which was all child switch driven. Hence why it currently the way it is. The child switch has many attributes about the matched Google item what your current switch won’t have. May not be important to your current use case but it is for others.

I can explore moving that functionality to additional actions when I have some free time over the holidays.

3 Likes

Is anyone else having their html tags stripped from the notification output text in RuleMachine?

My email notifications are just a wall of text, so I'm trying to add a line break, but the "" just disappears the second I hit "Done Editing Action."

I even tried the dishwasher example in the setup instructions and that gets stripped as well. Thought maybe it was just RuleMachine but I'm getting the same result in the Basic Rules App as well.

If HTML tags aren't possible, is there a way to make my email less wall-of-text-ey?

They are stripped for security reasons. Old post explaining:

I came across that post as well but thought that the users of this app must be using a workaround. The driver code in that thread threw up an Empty Parent error when I tried installing it so no dice there.

Am I misunderstanding the majority of people's use-case for the GCal search app? I must be, because not being able to add line-breaks to my email notifications became an issue on my very first email :thinking:

Gmail notifications are somewhat new to this app and the majority of the use cases for this app are search related querying calendar events and tasks to automate things within the home. I personally have several calendar queries that will turn on lights for wake up alarms, notify family and neighbors of USPS mail holidays and trash/recycling pickup, set my vacation switch to automate thermostat settings, prevent guest bedroom lights from turning off if guest is present, etc.

When I added Gmail search to the list it was logical for me to also add Gmail notifications too. But again that was added within the last year and this solution has existed well before Hubitat since it was created on the SmartThings platform many years ago and it was ported over and I have been enhancing the last several years.

My uses of email notifications are very limited to be honest and I added based on community request. I mostly use Pushover notifications. Hopefully others chime in here.

Have you tried \n for line break?

Know @danabw uses this for emails maybe he has some ideas.

I only use the email option to send emails to the Verizon email>text gateway, so not worrying about line breaks or any special characters...my messages are simple/short "this happened" notifications. Sorry I can't help.

1 Like

I did a little more testing and the Gmail Notification device allows you to insert <br> and it works:
image
Resulting email...
image

So the HTML stripping is definitely a RM and Basic rule situation as I confirmed that the BR's were being removed. I even tried to use a hub variable and insert the <br> and it also stripped them out.

I am sorry for this situation but this isn't a problem with the GCal app or device, its a HE hub UI situation causing it. You might consider opening a feature request in the Rule Machine category and request something to allow line breaks to be allowed.

1 Like

@bpkeeber sorry for yet another reply, thought of a work around I could create within this solution. I tested the use of the ASCII \n within the message and unfortunately it doesn't cause a line break but I added a few lines of code within the parent GCal Search app and I can substitute that for the actual <br> that is necessary to cause a line break.

My test RM app action:
image

Resulting email:
image

I will add it to the next release but in the mean time you could add these few lines of code to your existing GCal Search app code. Insert the following lines:

if (message.indexOf("\\n") > -1) {
	message = message.replace("\\n", "<br>")
}

Between lines 1096 and 1098 like the following:

Then include a \n in your rules and it should turn it into a new line.

1 Like

Version 4.6.0 has been posted to Github and HPM:

  • Added ability to turn on and off other existing switches in the Additional Actions settings. A child switch is no longer required to do so. If this was setup previously, the upgrade process will move the settings to Additional Actions. Thanks @mboisson for the suggestion!
  • Added the ability to enter '\n' within a Gmail notification message which will cause a carriage return within the email sent. In recent versions HTML is automatically stripped so this is a work around for new lines within email notifications. Thanks @bpkeeber for the idea!
  • When selecting switches in the various Additional Actions settings, the filter box is now available to quickly find specific switches.
2 Likes

I see that you've already published the updated version 4.6.0 :hushed: This is fantastic! thank you so much.

I appreciate your consideration immensely.

Can't wait to upgrade my automations with some shiny new
\nline
:sparkles: line :sparkles:
\nline
:sparkles: breaks :sparkles:
:sunglasses:

1 Like

This is fantastic, thank you -- I only use the GMail part right now (to enable Email/SMS based on events), but it works great.

Small bugfix (for your next release) -- if a child device is actually disabled on the Devices page, the code in the GCal_Search.groovy throws a null pointer exception at getNotificationDevices().

You could change lines 253/254 to have devPrefs?. instead of devPrefs. and then it shows the line correctly, but with null values of course.

2 Likes

Welcome to the community. Appreciate the bug report and solution. I am traveling this week on business but will get this resolved next week.

2 Likes