X10 Community Forum

📱🖥️PiX10Hub ( Always Evolving Open Source) => 💬General Discussion => 📝User created HG Scripts (programs/macros/widgets) => Topic started by: soxfan1966 on January 17, 2019, 04:00:09 PM

Title: Email notification
Post by: soxfan1966 on January 17, 2019, 04:00:09 PM
Is there a way to use the HomeGenie email notification when a certain x10 module gets triggered?  Or is that feature restricted to sensors / security items?
Title: Re: Email notification
Post by: bkenobi on January 17, 2019, 04:15:30 PM
If HG doesn't do something you like by default, there is almost certainly a way to make it happen since HG is open source and has real programming available via apps.  That said, you should be able to easily modify an existing app to provide notification the way you need.  I do not have a sample code available at this time so I can't post a solution.  If I get a chance, I will look to see if I have anything in my backup/snippets section.
Title: Re: Email notification
Post by: Tuicemen on January 17, 2019, 04:25:54 PM
Is there a way to use the HomeGenie email notification when a certain x10 module gets triggered?  Or is that feature restricted to sensors / security items?
yes!
 I believe I included a garage door notification macro in the PXH HomeGenie you just need to edit this for the module you wish and the message you wish. You can create several copies of this for different email or SMS notification messages. ;)
Title: Re: Email notification
Post by: soxfan1966 on January 17, 2019, 04:30:43 PM
I saw the garage door program but didn't see how to tie it to a module.  Will give that a try tomorrow.  Thx
Title: Re: Email notification
Post by: Tuicemen on January 17, 2019, 05:18:01 PM
You have to create a macro (and activate it) that triggers the Garage door program  when the device you wish to trigger it is detected. I haven't set this up or the email camera pictures which this is based off here in the city but it is setup at my off grid place.
I'll see about logging in there and  getting the specifics. if you need extra help.
Title: Re: Email notification
Post by: Tuicemen on January 18, 2019, 08:57:21 AM
Ok checked my off grid setup and it looks like I was mistaken in how to set this up. :-[ B:(
I'm using a call to HA-Bridge which in turn sends a call back to the HG API.
Not the cleanest method but it works. bkenobi may have a cleaner script.
You should beable to make a custom APi call in a macro but I've not played with that option as yet.
 >!

Title: Re: Email notification
Post by: bkenobi on January 18, 2019, 11:11:30 AM
I assumed Tuicemen would have something so I didn't check last night.  I'll put it on my to do list this weekend.  Hopefully I get all tasks complete so I can provide something.
Title: Re: Email notification
Post by: petera on January 18, 2019, 02:41:30 PM
In the meantime have a look at this HG video. Gives you a general idea how the triggering and notification system works. It should explain and help you to to create a macro to do this. https://m.youtube.com/watch?v=jsL_fAJ5-5w

You're requirement is very basic so it's quite simple to create a macro to do what you need. Basically it's something along the lines

If Garage Door switches to On (triggered) send a notification to the following recipients. The automation behind the Alarm program covers everything you need. It can even flash your lights when the Garage Door is triggered.
Title: Re: Email notification
Post by: bkenobi on January 18, 2019, 05:06:22 PM
The email is pretty easy.  I write my code in C# so Wizard will be slightly different.  Still, it should be VERY easy to send notification.  If you want an example of sending a notification on a tested event, look at my check IP app on github.  Your code would be even shorter because you don't need to store the old IP and check it against the new one.  All you need to do is trigger based on the state of a module and, when triggered, send notification which could be hard coded.
Title: Re: Email notification
Post by: soxfan1966 on January 18, 2019, 05:07:45 PM
Thanks.  I will give things a try tomorrow (looks like we may be snowed in for a day).
Title: Re: Email notification
Post by: soxfan1966 on January 21, 2019, 08:30:55 AM
I watched the linked you tube video - makes sense.  But I do not need the full blown security program.  If I could create something that I could then link in a similar fashion to those X10 modules I wanted as an option in the dropdown (similar to the one for the auto off delay) that would be great (easy, usable and exactly what I was looking for).

I'm just not sure how to get that program option created.
Title: Re: Email notification
Post by: soxfan1966 on January 21, 2019, 08:52:08 AM
The video?  Petra had posted a few posts earlier and suggested I watch it.
Title: Re: Email notification
Post by: petera on January 21, 2019, 09:04:18 AM
You can create a new program and copy/paste the sections of the code from the Email Notification that you require if you wish.
Title: Re: Email notification
Post by: Tuicemen on January 21, 2019, 09:19:05 AM
I don't think the issue is the email program as the garage notification works with a simple click. What soxfan1966 I believe is having difficulty with is automating the send notification without use of the security program, but maybe I'm wrong here.
Title: Re: Email notification
Post by: soxfan1966 on January 21, 2019, 09:20:56 AM
Tuicemen, That is exactly what I am trying to do
Title: Re: Email notification
Post by: Tuicemen on January 21, 2019, 09:35:53 AM
it should be possible using the homegenie/automation/CustomAPI in the programcode section of the macro.

However since I've not been able to have any success with that though I've not played much with it. The API call that works for the garage notification from a browser is http://"your HG ip &Port"/api/HomeAutomation.HomeGenie/Automation/Programs.Run/1004

So maybe (and a pi expert can correct me if wrong) you just enter the number of the program to send the which in the case of the garage notification would be 1004
Title: Re: Email notification
Post by: bkenobi on January 21, 2019, 10:00:25 AM
My Check IP app does a few things that you don't need but it's pretty short C# code.  If you implemented via C#, sending an email is a 1 line command.  I split it into a few just to make the subject, text, and recipient have their own variables (not needed).  AFAIK, you should be able to send an email via the Wizard script too, though.  If so, you simply would hard code your response and set it to the module you want it triggered by.  The only issue might be multiple triggers sending a flood of emails depending on the type of module and how it is triggered.  That can be avoided by coding something with a timeout...but that's a little more complicated than you asked about.
Title: Re: Email notification
Post by: Tuicemen on January 21, 2019, 10:07:44 AM
AFAIK, you should be able to send an email via the Wizard script too, though.  If so, you simply would hard code your response and set it to the module you want it triggered by. 
this is where soxfan1966 is at as am I, how do you activate a program from a macro trigger? I've just started to play with this but I'm not having any luck yet.
Title: Re: Email notification
Post by: bkenobi on January 21, 2019, 10:15:53 AM
I haven't done it myself as I always use C# triggering.  But, I find that approach clumsy for simple tasks.  I have meant to look into it but I've never had a project that needed it, so it has slipped down the priorities.

FWIW - I highly recommend pseudo code for anything more than a single logic statement.  There is NO way I would try to code anything without knowing my overall goal.  Once a logical progression is determined, fleshing it out with real code in whatever language is selected is really easy.  Also, if the code needs to be ported to a different platform (different HA software, different language, etc) you are already 85% of the way there!  I lost my pseudo code for the Advanced Smart Lights (ASL) code which is annoying.  I was considering porting it to Python since I find it easier to code in than Gene's C# implementation.  If I had it still, I'd probably have made something for Home Assistant or Domoticz just to give it a try.
Title: Re: Email notification
Post by: Tuicemen on January 21, 2019, 10:33:50 AM
Ok think I have it working now from a simple x10 module status.
once you have your notification program saved (can be based off bkenobi's check IP or the garage notification) take note of the program number HG assigns to it.
In your macro program code add homegenie/program.run/value it the value place the number of the notification programHG asigned it.
Title: Re: Email notification
Post by: bkenobi on January 21, 2019, 02:28:56 PM
I forgot I had a test email program.  Change the extension to "hgx" from "txt", import into HG, and change the variables for subject, message text, and recipients to what you need.  Like I said, it's literally 1 line of code (4 if you make variables).