Skip to main content

Alexa, Turn on Computer

There is many ways to wake your computer up and put your computer to hibernate using Alexa.

I will use:

1. computer with cygwin enabled with sshd service
2. domoticz on a raspberry pi
3. ha-bridge on raspberry pi
4. Amazon echo

I'm more of a computer user than a developer, but I find that Domoticz is great as it helps non-developers download unix commands and allow a direct call to shell scripts.

More great things about Domoticz is that it convert HTTP POST to GET methods when you are using triggers that can't do POST to Philips Hue lights (I will cover that in another post)


Step 1: Setup a dummy hardware used for virtual switches



Step 2: Create a virtual sensor as a light switch called Computer

For the On script use:
script:///home/pi/domoticz/scripts/pc-wake.sh

The bash script should contain

#!/bin/bash
wakeonlan  BC:5F:F4:88:92:B6


For the Off script use:
script:///home/pi/domoticz/scripts/pc-hibernate.sh

This bash script contents are; (Replace X with the IP address of the computer)

#!/bin/bash
ssh user@192.168.1.X "shutdown /h" &


The off switch assumes you have an sshd service running on your computer with private keys installed on the raspberry pi with no password so it auto autenticates and runs without entering a password. Windows 10 command to hibernate is shutdown /h

You will need to google again to find out how to setup sshd, as it's too long to put into this post.


For ha-bridge to use this, add the domoticz command to Computer (Replace NN with switch ID, you can get this from the devices tab under the "Setup" drop down.

On
http://192.168.1.Y:8080/json.htm?type=command&param=switchlight&idx=NN&switchcmd=On

Off
http://192.168.1.Y:8080/json.htm?type=command&param=switchlight&idx=NN&switchcmd=Off


To use

Alexa, turn on computer
Alexa, turn off computer






Comments

Popular posts from this blog

Multiple Broadlink RM mini 3 integration using MQTT

Broadlink now has quite a lot of integration options almost out of the box. If you enable Broadlink IHC, you can directly link it to Alexa by giving the device a unique name.

There is a homebridge plug in for homekit integration but I haven't tried or tested this. https://lprhodes.github.io/slate/

I wanted to put the device in domoticz so I can have more control over what can trigger my broadlink. I decided to use broadlink-mqtt for this, which is a fairly easy method to trigger from any source.

Setup Instructions for broadlink-mqtt

1. git clone https://github.com/eschava/broadlink-mqtt

2. vi /home/pi/broadlink-mqtt/mqtt.conf

3. Update the mqtt.conf file with the device type set as multiple_lookup

device_type = 'multiple_lookup'
mqtt_multiple_subprefix_format = '{type}_{mac_nic}/'
4. Start the python script and check that it started and detected all the RM devices.
Check the log file to see what the IP / MAC addresses are. DEBUG Connected to RM2 Broadlink device at …

Fibaro HCL Virtual Device Slider

How to setup Fibaro home center lite (HCL) slider for virtual devices.

As the Fibaro HCL does not support LUA. The question was how to update the number value of the slider to send to the HTTP string. Thanks to this site which is a really good reference https://www.vesternet.com/resources/application-notes/apnt-88/

The 2 use cases here are;

Sonos HTTP API Volume

To allow for volume control for all Sonos devices, add a virtual device with the IP address for SONOS HTTP API and specify the default port to 5005. Create Slider and put the following text into the string.

GET /volume/_sliderValue_ HTTP/1.10x0D0x0A0x0D0x0A


Domotiz Virtual Devices

GET /json.htm?type=command&param=switchlight&idx=XX&switchcmd=Set%20Level&level=_sliderValue_ HTTP/1.10x0D0x0A0x0D0x0A

Replace XX with the device ID.

Restart Fibaro HCL when it stops working automatically

It seems that the Fibaro HCL seems to hang every now and then. Instead of trying to restart it regularly, which doesn't really work, as it's almost impossible to predict when this will happen.

This method checks that the HCL is actually running and in the event it stops working, trigger a script that will restart it.


1. Get a non Fibaro controlled power plug and scripts to control it.

I used a wifi smart plug, TP-link HS100 and downloaded the scripts from

https://blog.georgovassilis.com/2016/05/07/controlling-the-tp-link-hs100-wi-fi-smart-plug/

2. Create a bash script to restart the Fibaro, e.g. restart_fibaro.sh

#!/bin/bash

ip_addr=
scripts=

$scripts/tplink-smartplug.py -t $ip_addr -c off
sleep 10
$scripts/tplink-smartplug.py -t $ip_addr -c on


3. Create a test global variable in the Fibaro HCL

Go to the variables panel and create a test variable, e.g. Test


4. Add a cron entry to test that the Fibaro API is still working and restart if it's not.

The cron script is scheduled ev…