Monday, April 23, 2018

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.

Friday, April 13, 2018

HomeKit Outdoor Weather and Indoor Temperature

This post adds both outdoor temperature and indoor temperature to Apple Homekit.

Outdoor Weather / Temperature

Using homebridge-weather https://www.npmjs.com/package/homebridge-weather

Add the following weather accessory to the homebridge config.json

    "accessories": [
    {
      "accessory": "Weather",
      "apikey": "enter_your_own_key_here",
      "locationByCoordinates": "lat=your_lattitudelon=your_longitude",
      "name": "Weather"
    }
    ]


Indoor Temperature

I'm taking indoor temperature from the Fibaro HCL temperature sensor, i.e. Aeotec multi-sensor.

Option1: cron/bash file to extract temperature to load into Domoticz temperature device

In the earlier post, I created a batch file to extract the temperature via REST API from Fibaro HCL to upload to a domo device. Not the most graceful way to do it, but it old school and works.


Option 2: Create a MQTT temperature feed using node-red

Another way, I just setup is using Node-red to keep pulling the temperature from the sensor and publishing it to domoticz/in topic to update the domoticz vitual device.

This is installed using https://www.npmjs.com/package/homebridge-mqtt-temperature This requires you to run mosquitto mqtt and node-red locally.

There's probably a few more things you can actually do with MQTT, so I've decided to move to MQTT instead and reduce the number of cron jobs.



  • The timestamp that triggers the flow can be set to repeat on interval of 10 mins.


  • The HTTP input "Room Temp" is the device URL from Fibaro. 

E.g. http://user:password@192.168.1.XX:80/api/panels/temperature?type=devices&method=single&id=XX

Replace the username, password, IP address and device ID.

  • Split is an easy way to remove the square brackets [] from the string output.


  • Fibaro to Temp function to re-write the JSON for Domoticz

The customised function will extract the TemperatureH value from the return JSON string and insert the domotics JSON format into domoticz/in topic for domoticz to update the virtual temperature device.

E.g.

var temperature =  msg.payload.temperatureH;
msg2 = {};
msg2.payload = '{ "idx" : XX, "nvalue" : 0, "svalue" : "'+temperature+'"}';
return msg2;

Again replace the XX with the Domoticz device ID.



Thursday, April 12, 2018

Automating Samsung MU6100 Series K

Finally upgraded to a new Samsung 4K TV and iSamsungTV stopped working. The good thing is that so have most people and there is a new app, samsungctl https://github.com/Ape/samsungctl which  allows command line interface to the TV using websocket, because everyone needs a to open a terminal window to change a channel.

I used this link to install samsungctl https://www.domoticz.com/wiki/Plugins/SamsungTV.html

Basically I needed to

  • sudo pip3 install samsungctl
  • sudo pip3 install websocket-client


After the installation, I had some error messages, i.e. "AttributeError: 'numpy.ndarray' object has no attribute 'tobytes'", which was solved by;
  • sudo pip3 install numpy --upgrade

The new TV can be turned on with WakeOnLAN now. This makes my Broadlink RM3 fairly redundant as the older Samsung wasn't able to turn on hence, I needed the IR blaster before.

Control Sonos outside your home using HomeKit

Applying the same concept as the Aeotec Dimmer for Homekit control, we can also use the Domoticz virtual dimmer to control the Sonos using node-sonos-http-api.

Homekit > Domoticz Virtual Dimmer (LUA) > node-sonos-http-api > Sonos

I'm starting to derive a shorter version of the LUA script for easier maintenance and using the base On and Off action commands on Virtual Device configuration page. Replace the IP address with the raspberry pi running node-sonos-htttp-api.

Virtual Device Name SonosOne_Volume

Action On Command: http://192.168.1.XX:5005/Sonos%20One/play
Action Off Command: http://192.168.1.XX:5005/Sonos%20One/pause


LUA script

/home/pi/domoticz/scripts/lua/script_device_SonosOne_Volume.lua


commandArray = {}

DEV='SonosOne_Volume'

if otherdevices[DEV] == 'Off' then
        os.execute('curl "http://192.168.1.XX:5005/Sonos%20One/pause"')
else
        Level = otherdevices_svalues[DEV]
        os.execute('curl "http://192.168.1.XX:5005/Sonos%20One/volume/"'..Level)
end

return commandArray


Wednesday, April 11, 2018

Extract temperature from Fibaro HCL to Homekit Room

For Apple mobile users who want to know the temperature of a room in Apple home using a temperature sensor from Fibaro HCL

Automation Flow:

Aeotec light/temp sensor > Fibaro HCL > bash script >; Domoticz virtual device > homebridge/homekit


Setup Steps

Step 1. Create a temperature virtual device in Domoticz and take note of the device id.

Step 2. Create a bash file with the following script, replacing the XX and user:password fields.


#!/bin/bash
status=/home/pi/scripts/temperature
domo_idx=XX
fib_idx=XX

curl "http://user:password@XX.XX.XX.XX/api/panels/temperature?type=devices&method=single&id="$fib_idx > $status
temperature=`cat $status |  sed 's/[{}]//g' |  awk -F : '{print $3}' | awk -F , '{print $1}'`

curl "http://XX.XX.XX.XX:8080/json.htm?type=command&param=udevice&idx="$domo_idx"&nvalue=0&svalue="$temperature


Step 3. Create a cron entry to run this script every 5 or 10 mins (temperature doesn't change that quickly)


Home Automation High Level Components

Maybe to put more context into the previous post of a slow build out of home automation components, here's a big picture integration diagram on how everything works together to date.




User Interaction

  • Mobile Apps
  • Voice Commands
  • Cloud Services


Integration Components
  • Home Automation Bridges
  • Domoticz
  • MQTT
  • Scripts (Python, Bash, LUA, etc.)

Connectivity Methods
  • Z-Wave (Fibaro)
  • Zigabee (Philips Hue)
  • Sonos wireless mesh
  • Wifi and LAN
  • Bluetooth Low Energy (BLE)
  • Infra-red

Automation Devices
  • Lights, Smart Dimmers
  • Smart Power plugs
  • Temperature, humidity and light sensors
  • Door sensors
  • Cameras
  • Network speaker system
  • Smart TV
  • Air-Conditioners / Thermostats


Use Homekit to control Fibaro HCL Z-Wave Dimmer



Home Automation Flow

Siri > Homebridge > Domoticz (LUA) > Fibaro HCL > Aeotec Nano Dimmer

Assume that Homebridge, Domoticz and Fibaro is already setup. The homebridge config.json file should have a room reference to avoid Homekit showing all devices

{
    "bridge": {
        "name": "Homebridge",
        "username": "CC:21:3E:E4:DE:33",
        "port": 51826,
        "pin": "031-45-154"
    },
    "description": "Configuration file for (e)xtended Domoticz platform.",
    "platforms": [
        {
            "platform": "eDomoticz",
            "name": "eDomoticz",
            "server": "127.0.0.1",
            "port": "8080",
            "ssl": 0,
            "roomid": 2,
            "mqtt": 1
        }
    ],
    "accessories": [
    ]
}



Step 1. Create a new domoticz virtual device example name "My_Dimmer"

Step 2. Add the virtual device to the Homebridge assigned Room "roomid" that is assigned for devices that Homekit will control.

Step 3: Create a new lua script file with the device name in this folder

/home/pi/domoticz/scripts/lua

The script name is important. For the device with the name "My_Dimmer". create the script "script_device_My_Dimmer.lua"

The whole path is as such.

/home/pi/domoticz/scripts/lua/script_device_My_Dimmer.lua

Insert the following to the script file, replacing user:password and device IDs. Script as follows:


commandArray = {}

DEV='My_Dimmer'

if otherdevices[DEV] == 'Off' then
        os.execute('curl "http://:@:80/api/callAction?deviceID=&name=turnOff"')
else
        Level = otherdevices_svalues[DEV]
=        os.execute('curl "http://user:password@:80/api/callAction?deviceID=&name=setValue&arg1="'..Level)
end

return commandArray



Important Note: name your dimmer My_Dimmer so that the name is consistent in the device and in the script for it to work.


Splitting the home network

Who wouldn't want to separate the traffic at home for security reasons. The more common ones include wireless guest and wireless users. ...