Has anyone found a way to send some kind of text input to HA, e.g. via SMS or similar that can be used in Automations?
I am thinking about building a simple console of sorts that can respond to text input with actions. An example usecase would be to run an ap[p that emails me battery levels when I text “Battery”.
Does it have to be text? Could you use the imap e-mail sensor? From what I have gathered that would allow you to send an e-mail with a specific subject/body and HA would recognize it and you could take action based on that sensor state.
If I had to do this, I would probably use a Command Line Sensor to check an email account. The bash one-liner below (credit to this page) will log into a gmail account and print the sender, subject, and first line or so of the most recent emails in the inbox. (Set up a new account just for this feature, and add a filter to only allow mail from whitelisted addresses so there are no security worries). Then when you want to send a command, just send an email to that account with the command you want in the subject or body. Use a regex (in bash, hass, or modify the perl one in the command) to process the text however you need.
I do something similar with a couple accounts - for example, I made a “quotable” inbox that functions as a quote book for my family. Whenever the kids (or less frequently my wife or I) say something really funny or memorable, we just type it into an email on our phone and send it off to the quotable box. A script checks that box every few hours, extracts the quotes, adds a timestamp and attribution, puts the text into rotation on a module running on our smart mirror, and also imagemagicks them into jpgs that rotate along with family photos on our photoframes (really just hacked 7" kindle fires). We use a similar process for family pictures - “share” them to a specific email address, a script checks it, pulls down the attachments, and adds them to the frames.
Not sure if that is what you’re looking for or not. I can add code if it would help.
I’m guessing the use case is a mobile phone to your HA install at home or similar?
If that’s the case one way of doing this is to synchronise a text file between your phone and your HA install.
Modify the text file on your phone, e.g. type in ‘battery’, that gets sync’d over to an identical text file on your HA install - then run a template sensor that checks the contents of the text file and responds accordingly.
‘Responds accordingly’ can be a new text file HA generates that then gets sync’d back to your phone, or a reply within the same text file. It really comes down to what interactions you want with your phone: text editing or something a bit more app-like.
So the remaining issues are: 1) how to do that Synchronising, and 2) how to make a handy app for your phone that avoids messing with text editors on a small phone screen.
I can fix #1 - I’ve outlined the steps in this post:
plus this one
Syncthing is also handy for sending photos / videos from your security cams, any data really, plus it’s fully encrypted and open-source too!
Number 2 - I’m very much on the bottom rung of that learning ladder.
Just looked around twilio as you peaked my curiosity. Seems the simplest way would to get a twilio number, forward the messages to an email and then scrape that.
Gotta go babysit my sick niece tomorrow, maybe Ill try and learn that.
Sadly, it isn’t. It’s a hodge podge of random un-commented hard coded punctuation soup spread across a bunch of different machines that is very specific to my local network and unlikely to be of much use to anyone other than as a solid one-time pad to encrypt state secrets.
That said, cleaning it up and making it available is on my to-do list. I’m just terrible at documentation.
It seems really easy with twilio once one knows exactly what they are doing, which I do not.
<?php
/**
* This section ensures that Twilio gets a response.
*/
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Response></Response>'; //Place the desired response (if any) here
/**
* This section actually sends the email.
*/
/* Your email address */
$to = "[email protected]";
$subject = "Message from {$_REQUEST['From']} at {$_REQUEST['To']}";
$message = "{$_REQUEST['Body']}";
$headers = "From: [email protected]"; // Who should it come from?
mail($to, $subject, $message, $headers);
this is an example I found that will email the sms to an address. I’v got that going and scraping it into a value.
I know there is an easier way to send the info directly into HA via a “post” (?)
I imagine the last line about has to do that magic, but i haven’t found the right way to do it in searching (probably because I don’t know what I looking for)
the above file has to be put on a web server, then linked on twilio on the incoming side of the sms service.