The following script example is cool but maybe not for everyone. (I’m not sure)
Using this script, you can make openHAB speak any message from an external host. For example when your cell phone rings, you can have openHAB announce the caller’s name. (By using the tasker app and by issue a http POST request to the REST API). Well, I leave it up to your imagination what you want to do with it.
First create an openHAB Item like this:
String Speak_This "Speak this [%s]" <text>
curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "Hello world" "http://OPENHABHOST:8080/rest/items/Speak_This/state"
Script can be downloaded here.
from lucid.rules import rule, addRule
from lucid.triggers import ItemStateUpdateTrigger
from lucid.speak import tts
Make openHAB speak a message that you've posted to the openHAB REST API from an external host
This script watches an openHAB string item, e.g: String Speak_This "Speak this [%s]" <text>
Use curl from an external host to set the item to the text string that shall be spoken
e.g. curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "Hello world" "http://OPENHABHOST:8080/rest/items/Speak_This/state"
def execute(self, modules, inputs):
Setting up Tasker
This is a bit beyond the scope of this thread, but in case you’d like to set up Tasker on your Android phone to announce the name of who is calling you (by a TTS spoken message on openHAB), I attach 3 tasker tasks xml backup files.
To use it:
- create 2 vars named OHSERVER and OHPORT. Set OHSERVER to Username:Password@myopenhab.org (Where Username and Password are your own login credentials to myopenHAB service). Set OHPORT to 443. In case you prefer to use your own LAN openHAB server instead, it should work too but then your openHAB Tasker scripts will only work while your phone is connected to your LAN Wifi.
- Restore the three attached task xml files.
- Create a profile in Tasker. Event: “Phone Ringing”, State: “Wifi Connected” and specify your Wifi’s SSID. (Use search while connected). Associate the profile with with the previously imported task named “Announce Caller”
Now you should be good to go. Ask your mother in law to call you, just to check!
Edit: Note, the tts function is currently implemented with the Sonos Speakers system in mind. It probably works for other systems as well but I should rename the variables to make it vendor independent.
ohSpeak.tsk.xml (486 Bytes)
ohRestAPI.tsk.xml (1018 Bytes)
Announce_Caller.tsk.xml (1.4 KB)