Monday, 17 October 2016

Change color and dim the lights when playing on steam.

Dim my lights and set the hue to blue when i start a game in my steam account. This was a bit tricky because i have to make a fake sensor make a automation on the game value instead of the state=online. It works very fastm, max delay from i start or end a game is around 1 minutt.
sensor:
- platform: steam_online
api_key: ***RETRACTED***
accounts:
- 76561198024292709
sensor templates:
platform: template
sensors:
playingonsteam:
value_template: "{% if is_state_attr('sensor.steam_76561198024292709', 'Game', 'None') %} False {% else %} True {% endif %}"
automation:
- alias: Start playing a game on steam
trigger:
platform: state
entity_id: sensor.playingonsteam
to: 'True'
from: 'False'
action:
service: scene.turn_on
entity_id: scene.kontorgame
- alias: Ended playing a game on steam
trigger:
platform: state
entity_id: sensor.playingonsteam
to: 'False'
from: 'True'
action:
service: scene.turn_on
entity_id: scene.kontorkoding
view raw gistfile1.txt hosted with ❤ by GitHub

Thursday, 13 October 2016

Easy steam scraping with BeautifulSoup


I wanted to make a sensor for my steam account to use for future projects. After some googling i found BeautifulSoup. I framework to search with in text/html and xml. After some fiddling i got it working. To get steam working you need a working public profile page.

Install BeautifulSoup

sudo apg-get update -y && sudo atp-get upgrade -y && sudo apt-get install python-bs4 -y

Steam scraper

from bs4 import BeautifulSoup
import urllib
r = urllib.urlopen('http://steamcommunity.com/profiles/76561198024292709').read()
soup = BeautifulSoup(r,"html.parser")
for row in soup.find_all('div',attrs={"class" : "profile_in_game_name"}):
print row.text
view raw gistfile1.txt hosted with ❤ by GitHub
Will return blank if Im not playing anything or the name of the game if im playing.

Referance
https://www.crummy.com/software/BeautifulSoup/bs4/doc/

Raspian commandline network speedtest

To check internet speed on your raspberry do the following steps.


  • sudo apg-get update
  • sudo apt-get upgrade
  • sudo apt-get install python-pip
  • sudo easy_install speedtest-cli


Then simply type speedtest-cli and you will get something like this



Monday, 10 October 2016

Smartify a simple heater


I needed to make a controller for my cheap and simple heater. It don't have any termostat and the setting are really strange and I could not find the correct settings, either too hot or too cold. I connected a 433 sender to a raspberry pi and made a flask web API. I then added a switch in Home Assistant that run a curl command to the other pi.

Hardware

Parts

Wiring

  • VCC -> pin 1 3,3Volt
  • Gnd -> pin 6 Gnd
  • Date/Data/signdal -> GPIO 17 (pin11)

Software

piHomeEasy
cd ~
sudo apt-get install git-core
git clone git://git.drogon.net/wiringPi
cd wiringPi
sudo ./build
git clone git://github.com/nbogojevic/piHomeEasy.git
make
sudo make install
sudo apt-get install python-flask
view raw gistfile1.txt hosted with ❤ by GitHub

Flask code

 
from flask import Flask, url_for
import os
app = Flask(__name__)
@app.route('/')
def api_root():
return 'Nexa gateway'
@app.route('/on/<deviceid>/<receiverid>')
def api_nexadeviceon(deviceid,receiverid):
cmd = 'sudo piHomeEasy 0 '+ deviceid + ' ' + receiverid + ' on'
os.system(cmd)
return 'turning device ' + deviceid + ' on.'
@app.route('/off/<deviceid>/<receiverid>')
def api_nexadeviceoff(deviceid,receiverid):
cmd = 'sudo piHomeEasy 0 '+ deviceid + ' ' + receiverid + ' off'
os.system(cmd)
return 'turning device ' + deviceid + ' off.'
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
view raw gistfile1.txt hosted with ❤ by GitHub

Homeassistant

switch:
platform: command_line
switches:
officeheater:
command_on: 'curl http://<<ip>>:5000/on/1509/5'
command_off: 'curl http://<<ip>>:5000/off/1509/5'
view raw gistfile1.txt hosted with ❤ by GitHub

Referances

Wednesday, 5 October 2016

NodeMCU Rgb controller


I made a easy IR controller for my generic RGB light strip. You can simply use curl(like http://IP-ADDR/rgbon) to turn on/off, dim the light or do some silly effects.

Arduino code:
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266mDNS.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
//RGB VALUES
#define LED_ON 0XFFE01F
#define LED_OFF 0xFF609F
#define LED_BRIGHTNESS_UP 0xFFA05F
#define LED_BRIGHTNESS_DOWN 0xFF20DF
#define LED_FLASH 0xFFF00F
#define LED_STROBE 0xFFE817
#define LED_FADE 0xFFD827
#define LED_SMOOTH 0xFFC837
#define LED_RED 0xFF906F
#define LED_GREEN 0XFF10EF
#define LED_BLUE 0xFF50AF
#define LED_WHITE 0xFFD02F
#define LED_ORANGE 0xFFB04F
#define LED_YELLOW_DARK 0xFFA857
#define LED_YELLOW_MEDIUM 0xFF9867
#define LED_YELLOW_LIGHT 0xFF8877
#define LED_GREEN_LIGHT 0XFF30CF
#define LED_GREEN_BLUE1 0XFF28D7
#define LED_GREEN_BLUE2 0XFF18E7
#define LED_GREEN_BLUE3 0XFF08F7
#define LED_BLUE_RED 0XFF708F
#define LED_PURPLE_DARK 0XFF6897
#define LED_PURPLE_LIGHT 0XFF58A7
#define LED_PINK 0XFF48B7
ESP8266WebServer server(80);
const char* ssid = "";
const char* password = "";
IRsend irsend(D3);
void handleOk() {
server.send(200, "text/plain", "ok");
}
void handleRoot() {
server.send(200, "text/plain", "hello from esp8266!");
}
void handlergbOn() {
irsend.sendNEC(0XFFE01F, 32);
handleOk();
}
void handlergbOff() {
irsend.sendNEC(0xFF609F, 32);
handleOk();
}
void setup()
{
irsend.begin();
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
// on/off
server.on("/rgbon", handlergbOn);
server.on("/rgboff", handlergbOff);
//effects
server.on("/rgbbrightup", []() {
irsend.sendNEC(LED_BRIGHTNESS_UP, 32);
handleOk();
});
server.on("/rgbbrightdown", []() {
irsend.sendNEC(LED_BRIGHTNESS_DOWN, 32);
handleOk();
});
server.on("/rgbflash", []() {
irsend.sendNEC(LED_FLASH, 32);
handleOk();
});
server.on("/rgstrobe", []() {
irsend.sendNEC(LED_STROBE, 32);
handleOk();
});
server.on("/rgbfade", []() {
irsend.sendNEC(LED_FADE, 32);
handleOk();
});
server.on("/rgbsmooth", []() {
irsend.sendNEC(LED_SMOOTH, 32);
handleOk();
});
server.on("/rgbred", []() {
irsend.sendNEC(LED_RED, 32);
handleOk();
});
server.on("/rgbgreen", []() {
irsend.sendNEC(LED_GREEN, 32);
handleOk();
});
server.on("/rgbblue", []() {
irsend.sendNEC(LED_BLUE, 32);
handleOk();
});
server.on("/rgbwhite", []() {
irsend.sendNEC(LED_WHITE, 32);
handleOk();
});
server.on("/rgborange", []() {
irsend.sendNEC(LED_ORANGE, 32);
handleOk();
});
server.on("/rgbyellowdark", []() {
irsend.sendNEC(LED_YELLOW_DARK, 32);
handleOk();
});
server.on("/rgbyellowmedium", []() {
irsend.sendNEC(LED_YELLOW_MEDIUM, 32);
handleOk();
});
server.on("/rgbyellowlight", []() {
irsend.sendNEC(LED_YELLOW_LIGHT, 32);
handleOk();
});
server.on("/rgbgreenlight", []() {
irsend.sendNEC(LED_GREEN_LIGHT, 32);
handleOk();
});
server.on("/rgbbluered", []() {
irsend.sendNEC(LED_BLUE_RED, 32);
handleOk();
});
server.on("/rgbpurpledark", []() {
irsend.sendNEC(LED_PURPLE_DARK, 32);
handleOk();
});
server.on("/rgbpurplelight", []() {
irsend.sendNEC(LED_PURPLE_LIGHT, 32);
handleOk();
});
server.on("/rgbpink", []() {
irsend.sendNEC(LED_PINK, 32);
handleOk();
});
server.on("/rgbgreenblue2", []() {
irsend.sendNEC(LED_GREEN_BLUE1, 32);
handleOk();
});
server.on("/rgbgreenblue2", []() {
irsend.sendNEC(LED_GREEN_BLUE2, 32);
handleOk();
});
server.on("/rgbgreenblue3", []() {
irsend.sendNEC(LED_GREEN_BLUE3, 32);
handleOk();
});
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}
view raw gistfile1.txt hosted with ❤ by GitHub
Pinlayout:
Vin(USB 5v): Vcc
Gnd: Gnd
D3: Signal



Parts:
Home Assistant Implentation
switch:
platform: command_line
switches:
kontordeskrgb:
command_on: 'curl http://<<IP ADDR>>/rgbon'
command_off: 'curl http://<<IP ADDR>>/rgboff'
view raw gistfile1.txt hosted with ❤ by GitHub



Simple 3d printed prototype box with everything mounted