Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr4331 :: Re-inventing the light switch

Lee does some home automation with Bash, Python and Apache Cordova

<< First, < Previous, Next > Latest >>

Hosted by Lee on Monday, 2025-03-10 is flagged as Clean and is released under a CC-BY-SA license.
python, bash, cordova. (Be the first).

Listen in ogg, opus, or mp3 format. Play now:

Duration: 00:09:36
Download the transcription and subtitles.

Home Automation.

A open series on anything related to Smart Home, or Internet Of Things

Bulbs


Wiz Connected smart light bulbs


Exploit


Article about hacking the lights


Source Code


Source code of the hack


Cordova


Apache Cordova framework for mobile apps


Cordova Plugin


SSH Connect Cordova Plugin


KDE Widgets



Mobile Interface



Code


Python Script


wiz-hack.py

import socket
import time
import random
import sys
​
if len(sys.argv) < 3:
     print(help)
     exit()
IP = sys.argv[1]
​
on = """{"params":{"orig":"andr","state":true},"id":6,"method":"setPilot"}"""
off = """{"params":{"orig":"andr","state":false},"id":6,"method":"setPilot"}"""
​
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((IP, 38899))
if sys.argv[2] != "on" and sys.argv[2] != "off":
   print("Changing lights color")
   b = sys.argv[2]
   color_send = """{"method":"setPilot","params":{"r":""" + str(255) + ""","g":""" + str(255)  + ""","b":""" + str(255) + ""","dimming":""" + str(b) + """}}"""
   print(color_send)
   s.sendall(bytes(color_send, "utf-8"))
   s.close()
elif sys.argv[2] == "on":
    print("Turning on the lights")
    s.sendall(bytes(on, "utf-8"))
    s.close()
elif sys.argv[2] == "off":
    print("Turning off the lights")
    s.sendall(bytes(off, "utf-8"))
    s.close()


Shell Scripts


on.sh

#!/bin/sh
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.94 on
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.177 on
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.207 on
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.254 on
​


off.sh

#!/bin/sh
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.94 off
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.177 off
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.207 off
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.254 off


light.sh

#!/bin/sh
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.94 "$1"
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.177 "$1"
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.207 "$1"
/usr/bin/python /usr/local/bin/wiz-hack.py 192.168.0.254 "$1"


Mobile App


index.html (excerpt)

...
<h1>Light Control</h1>
​
<button id="onButton">On</button>
<button id="offButton">Off</button>
​
<br><br>
​
<label for="brightnessSlider">Brightness:</label>
<input type="range" id="brightnessSlider" min="0" max="100" value="50">
​
<script src="cordova.js"></script>
<script src="js/index.js"></script>


index.js

const user = "user";
const password = "redacted_password";
const host = "192.168.0.218";
const port = "22";
​
var sshConnect;
​
function on() {
   sshConnect.connect(user, password, host, port, () => {
       sshConnect.executeCommand('on.sh', function() {
           sshConnect.disconnect();
       });
   });
}
​
function off() {
   sshConnect.connect(user, password, host, port, () => {
       sshConnect.executeCommand('off.sh', function() {
           sshConnect.disconnect();
       });
   });
}
​
function brightness(level) {
   sshConnect.connect(user, password, host, port, () => {
       sshConnect.executeCommand('light.sh '+level, function() {
           sshConnect.disconnect();
       });
   });
}    
​
document.addEventListener('deviceready', onDeviceReady, false);
​
function onDeviceReady() {
   sshConnect = cordova.plugins.sshConnect;
​
   document.getElementById("onButton").addEventListener("click", () => {
     // Send "on" command to light
     console.log("Light turned on");
     on();
   });
​
   document.getElementById("offButton").addEventListener("click", () => {
     // Send "off" command to light
     console.log("Light turned off");
     off();
   });
​
   document.getElementById("brightnessSlider").addEventListener("input", () => {
     const level = document.getElementById("brightnessSlider").value;
     // Send brightness value to light
     console.log("Brightness set to:", level);
     brightness(level);
   });
}



Comments

Subscribe to the comments RSS feed.

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
Who is the host of this show?
What does HPR mean to you?