How to parse an email (gmail) and change status of an item depending on the mail content

Hi

I’m running OpenHab 2.1.0-1.

I’ve been looking for a solution to translate an email sent from my Synology Diskstation, notifying me that my system is running on the UPS battery power into an item update telling me that my there is a power outage.

I’ve been looking at ifttt combined with gmail and MyOpenHab, but I can’t find any decent ways of achieving this.

Are there any bindings that can parse on IMAP or with a gmail integration?

Thanks
Thomas

1 Like

I’ve linked email to openHAB using IFTTT

I setup a single purpose gmail account. Link that to IFTTT. Create a String item ‘gmailSubject’. Then my IFTTT recipe makes a GET web request as follows:

https://user:password@url:port/classicui/CMD?gmailSubject={{Subject}}

So any email sent to the gmail account updates the item with whatever’s in the subject of the email.

Have you considered looking into the SNMP binding which should let OH get the information directly from the Synology rather than going through this roundabout way of getting the info from an email.

1 Like

I own such a beast as well but never noticed that it supports SNMP natively. This opens a bunch of possibilities, and UPS power failure detection is surely a fine thing. My number of bindings raises to a dozen.

To be honest, I just guessed that surely it must support SNMP. :smiley: I’m glad I guessed correctly.

Yay - thanks for the SNMP heads up :slight_smile:

I ended up creating an item for the Synology SNMP upsInfoStatus:

String NAS_UPS_STATUS "Status on the UPS [%s]" { snmp="<[192.168.x.x:DS:.1.3.6.1.4.1.6574.4.2.1.0:10000]" }

It has a normal status of “OL” and when discharging “OL DISCHRG” or “OB DISCHRG” - still not sure what OB is for because the status is “OL CHRG” or “OB CHRG” when charging, so it can’t be OB for battery powered…

Anyway - I created a rule to first of all change the status of a switch item depending on if the UPS is charging or discharging.

rule "Power out"
when
	Item NAS_UPS_STATUS received update
then
	UPS_POWER.state=NAS_UPS_STATUS.state
	if(NAS_UPS_STATUS.state=="OL DISCHRG"||NAS_UPS_STATUS.state=="OB DISCHRG"){
		HOUSE_POWER.sendCommand(OFF)
		
	}else{
		if(NAS_UPS_STATUS.state=="OL CHRG"||NAS_UPS_STATUS.state=="OB CHRG"||NAS_UPS_STATUS.state=="OL"){
			HOUSE_POWER.sendCommand(ON)
		}
	}
end	

If there is a better way of doing it, I’m open to suggestions :slight_smile:

1 Like

Hi Dan

I tried figuring out how that works - I haven’t got any former experience with IFTTT, and after an hour or two researching, I still wasn’t any closer to figure out how to link the email or gmail service to sending a GET request or changing status on an item in OpenHab cloud…

Also the word recipe doesn’t seem to exist within IFTTT anymore - just applets and services. I tried setting up an applet with the gmail service but I couldn’t find a way to link it with the OpenHab service…

The following steps should do it:

  • connect gmail to your IFTTT account (searc* h/gmail)
  • connect webhooks to your IFTTT account (search/webhooks)
  • new applet
  • select a trigger, i.e. click the “plus” in the IFTTT logo, then select gmail
  • “any new email in inbox”
  • select the action, i.e. click the “that” and select webhooks
  • “make a web request”
  • then setup a GET web request as above

Dan

Would the openHAB channel work for this? Of course, assuming you have myopenhab.org set up with the Item you want to send the data to exposed to IFTTT.

Not sure - I don’t use myopenhab.org out of stability/security concerns (although I appreciate that exposing my password to IFTTT does not evidence the highest degree of paranoia…)

I actually go an applet up and semi working where I’m not using a web hook, but pointing at an item in myopenhab instead.
It fails on me, but I’m not sure if it’s the gmail service or the OpenHab service and unfortunately I don’t have the time to research it any deeper this week - To be continued when time permits :slight_smile:

The IFTTT/gmail link seems rock solid (at least it was until I wrote that)

1 Like

Sorry for “warming up” this old post, but I just wanted to thank you for this contribution. I now finally have a monitoring for power outage, awesome!

1 Like