Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
LarsBergqvist / configuration.yaml
Created February 7, 2017 20:10
Groups and default_view for Home Assistant
group:
groundfloor:
name: Ground floor
entities:
- switch.window_lights_downstairs
- switch.wall_lights_downstairs
- sensor.ground_floor_temp
- sensor.ground_floor_humidity
topfloor:
@LarsBergqvist
LarsBergqvist / configuration.yaml
Created February 7, 2017 20:05
RESTful switch configuration for Home Assistant
switch:
- platform: rest
name: 'Window lights upstairs'
resource: http://192.168.1.16:5000/Outlets/api/outlets/1/1
body_on: 'on'
body_off: 'off'
- platform: rest
name: 'Floor light upstairs'
resource: http://192.168.1.16:5000/Outlets/api/outlets/1/4
body_on: 'on'
@LarsBergqvist
LarsBergqvist / configuration.yaml
Created February 7, 2017 09:55
panel_iframe example for Home Assistant
panel_iframe:
charts:
title: 'Charts'
url: 'http://192.168.1.16:6001/ChartData'
icon: 'mdi:chart-line'
@LarsBergqvist
LarsBergqvist / configuration.yaml
Created February 7, 2017 08:41
MQTT sensor configuration for Home Assistant
sensor groundfloor:
- platform: mqtt
state_topic: "Home/GroundFloor/Temperature"
name: 'Ground floor temp'
unit_of_measurement: "C"
sensor outdoor:
- platform: mqtt
state_topic: "Home/Outdoor/Temperature"
name: 'Outdoor temp'
unit_of_measurement: "C"
@LarsBergqvist
LarsBergqvist / statestorage.py
Created February 7, 2017 08:19
Simple storage of states in a global dictionary
import threading
states = {}
lock = threading.Lock()
def get_state(groupNumber, buttonNumber):
key = str(groupNumber) + '_' + str(buttonNumber)
state = 'off'
lock.acquire()
@LarsBergqvist
LarsBergqvist / get_outlet_state.py
Created February 7, 2017 08:08
Flask GET route. Return the current state of an outlet switch
@app.route("/Outlets/api/outlets/<int:groupNumber>/<int:buttonNumber>",methods=["GET"])
def get_outlet_state(groupNumber, buttonNumber):
return statestorage.get_state(groupNumber, buttonNumber)
@LarsBergqvist
LarsBergqvist / jsonandrawdatapayloads.py
Created February 7, 2017 08:04
Accept both json and raw data payloads for the state of the switch
@app.route("/Outlets/api/outlets/<int:groupNumber>/<int:buttonNumber>",methods=["PUT","POST"])
def update_outlet_state(groupNumber, buttonNumber):
state=None
if request.json is not None:
state=request.json.get("state")
else:
state=request.data
if (state is None):
abort(400)
@LarsBergqvist
LarsBergqvist / putandpost.py
Created February 7, 2017 07:59
Flask route with put and post
@app.route("/Outlets/api/outlets/<int:groupNumber>/<int:buttonNumber>",methods=["PUT","POST"])
def update_outlet_state(groupNumber, buttonNumber):
@LarsBergqvist
LarsBergqvist / configuration.yaml
Last active February 7, 2017 07:45
RESTful switch definitions for Home Assistant
switch upstairs_windows:
- platform: rest
name: 'Windows upstairs'
resource: http://192.168.1.16:5000/Outlets/api/outlets/1/1
body_on: 'on'
body_off: 'off'
switch downstairs_windows:
- platform: rest
name: 'Windows downstairs'
@LarsBergqvist
LarsBergqvist / subscriber_adafruit_proxy.py
Last active March 1, 2018 12:52
Subscribes to messages via a local MQTT broker and forwards them to a cloud service (Adafruit IO)
#!/usr/bin/env python3
import paho.mqtt.client as mqtt
import datetime
import time
from Adafruit_IO import MQTTClient
from adafruit_credentials import ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY
from mylogger import logger
#
# Subscribes to messages via a local MQTT broker