I have managed to control my lights through HA that are connected to the hub on an echo plus. The idea came after reading another post . Thanks!
Quite new to this and 100% new to shell (thanks google) so i thought i would right a quick little how to guide and share my scripts hoping it will help someone
What it does
Once setup, There will be a service available. It uses a script which allows you to start a routine (and other things) via the shell script. It also saves a log file with the last action.
What it doesn’t
It doesnt allow you to control the brightness or colour (directly) you can turn the devices off and on (although you can set more routines up with brightness colour etc and run them) I have only tried this with lights not with switches, Don’t see why it wouldn’t work though.
How to setup
Quite a few things to setup to get this working;
My script is simple:
#! /bin/sh
filename=$(basename -- "$0")
logdest=/home/homeassistant/scripts/log.txt
timestamp=$(date +%T)
name=$(echo "$filename" | cut -f 1 -d '.')
logoutput="["$timestamp"] "$name" was switched on"
/home/homeassistant/scripts/alexa_remote_control.sh -e automation:$name
echo $logoutput >> $logdest
You can download the alexa script from here
I saved these files in /home/homeassistant/scripts (if you change this you will need to edit my “newlight.sh” or logdest variable with the new path)
Edit the Alexa_remote_controll.sh script with your region & amazon details.
Test it is working by running
sudo ./path/to/alexa_remote_control.sh -a
if everything is ok with the login then it should print your Echo plus or echo dot names.
2 x routines need to be made in the alexa app. One controlling the light to turn on (You can at this point add anything you want to the routine. but i kept it simple) and one to turn it back off again. Name these like mylighton or mylightoff. (The name comes from what ever you type in the “Voice” part when setting up the routine)
Back to the pi again.
sudo cp newlight.sh mylighton.sh
This just makes a copy of my newlight.sh script, My script uses the filename minus the .sh in the command it sends to the alexa_remote_control.sh . So its important its named exactly the way it is in the alexa app on your phone!
Run:
sudo nano /home/homeassistant/.homeassistant/configuration.yaml
And copy platform and the path to your script and script names:
shell_command:
mylighton: /home/homeassistant/scripts/mylighton.sh
mylightoff: /home/homeassistant/scripts/mylightoff.sh
On HA check your config and if its ok restart it. Once restarted you should have 2 new services shell_command.mylighton & shell_command.mylightoff if you run these services it will turn your light on and off.
You now have limited control of your Zigbee bulbs attached to alexa! From here you can set them up in scripts within HA to call the new services
Optional:
I also set a switch up to which holds a sort of state for the bulb using input_boolean and allows you to control it from the GUI
input_boolean:
myroomboolean:
name: My room light boolean
switch:
platform: template
switches:
myroom:
friendly_name: My Room
value_template: >
{{ is_state('input_boolean.myroomboolean', 'on') }}
turn_on:
- service: input_boolean.turn_on
entity_id: input_boolean.myroomboolean
- service: script.mylighton
turn_off:
- service: input_boolean.turn_off
entity_id: input_boolean.myroomboolean
- service: script.mylightoff
Thats it If this can be achieved in a better way (less scripts) please let me know. I just hope this helps somebody stuck like i was!
Thanks again to @ReneTode