Fundamental setup of sensors, data inputs and more ; full support for spark fun weather shield (see repo for adjusted ino sketch that makes it work with home-assistant.io)

This commit is contained in:
KemoNine 2019-05-04 00:23:34 +00:00
parent 2dccda89dd
commit 9e00d312ee
22 changed files with 607 additions and 308 deletions

View File

@ -7,3 +7,11 @@ Notes and information about my [home-automation.io](https://www.home-automation.
Unless otherwise stated the contents of this repository are licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](LICENSE.txt).
![cc-by-nc-sa](cc-by-nc-sa.png)
# Additional Credits
Large portions of this repo and config were adapted from the following sources.
- [https://github.com/renemarc/home-assistant-config/](https://github.com/renemarc/home-assistant-config/)
- [https://github.com/stanvx/Home-Assistant-Configuration](https://github.com/stanvx/Home-Assistant-Configuration)
- [https://www.awesome-ha.com/](https://www.awesome-ha.com/)

View File

@ -1,16 +1,18 @@
/*
Weather Shield Example
By: Nathan Seidle
SparkFun Electronics
Date: June 10th, 2016
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
Weather Shield Example
By: Nathan Seidle
SparkFun Electronics
Date: June 10th, 2016
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
This example prints the current humidity, air pressure, temperature and light levels.
This example prints the current humidity, air pressure, temperature and light levels.
The weather shield is capable of a lot. Be sure to checkout the other more advanced examples for creating
your own weather station.
The weather shield is capable of a lot. Be sure to checkout the other more advanced examples for creating
your own weather station.
*/
*/
#include <ArduinoJson.h>
#include <Wire.h> //I2C needed for sensors
#include "SparkFunMPL3115A2.h" //Pressure sensor - Search "SparkFun MPL3115" and install from Library Manager
@ -35,7 +37,6 @@ long lastSecond; //The millis counter to see when a second rolls by
void setup()
{
Serial.begin(9600);
Serial.println("Weather Shield Example");
pinMode(STAT_BLUE, OUTPUT); //Status LED Blue
pinMode(STAT_GREEN, OUTPUT); //Status LED Green
@ -54,17 +55,17 @@ void setup()
lastSecond = millis();
Serial.println("Weather Shield online!");
digitalWrite(STAT_GREEN, HIGH); //Signal online / active status
}
void loop()
{
//Print readings every second
if (millis() - lastSecond >= 1000)
//Print readings every 10 seconds
if (millis() - lastSecond >= 10000)
{
digitalWrite(STAT_BLUE, HIGH); //Blink stat LED
lastSecond += 1000;
lastSecond += 10000;
//Check Humidity Sensor
float humidity = myHumidity.readHumidity();
@ -74,7 +75,7 @@ void loop()
Serial.println("I2C communication to sensors is not working. Check solder connections.");
//Try re-initializing the I2C comm and the sensors
myPressure.begin();
myPressure.begin();
myPressure.setModeBarometer();
myPressure.setOversampleRate(7);
myPressure.enableEventFlags();
@ -82,38 +83,36 @@ void loop()
}
else
{
Serial.print("Humidity = ");
Serial.print(humidity);
Serial.print("%,");
DynamicJsonDocument jsonBuffer(1024);
jsonBuffer["humidity_percent"] = humidity; // %
float temp_h = myHumidity.readTemperature();
Serial.print(" temp_h = ");
Serial.print(temp_h, 2);
Serial.print("C,");
jsonBuffer["temp_c"] = temp_h; // C
//Check Pressure Sensor
float pressure = myPressure.readPressure();
Serial.print(" Pressure = ");
Serial.print(pressure);
Serial.print("Pa,");
jsonBuffer["pressure_pa"] = pressure; // Pa
//Check tempf from pressure sensor
float tempf = myPressure.readTempF();
Serial.print(" temp_p = ");
Serial.print(tempf, 2);
Serial.print("F,");
jsonBuffer["temp_f"] = tempf; // F
//Heat Index
float hi = heatIndex(tempf, humidity);
jsonBuffer["hi_f"] = hi; // F
jsonBuffer["hi_c"] = convertFtoC(hi); // C
//Check light sensor
float light_lvl = get_light_level();
Serial.print(" light_lvl = ");
Serial.print(light_lvl);
Serial.print("V,");
jsonBuffer["light_lvl_v"] = light_lvl; // V
//Check batt level
float batt_lvl = get_battery_level();
Serial.print(" VinPin = ");
Serial.print(batt_lvl);
Serial.print("V");
jsonBuffer["batt_lvl_v"] = batt_lvl; // V
// Print json sensor data
serializeJson(jsonBuffer, Serial);
Serial.println();
}
@ -156,3 +155,32 @@ float get_battery_level()
return (rawVoltage);
}
float convertFtoC(float f) {
return (f - 32) * 0.55555;
}
float heatIndex(float temperature, float percentHumidity)
{
float hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094));
if (hi > 79) {
hi = -42.379 +
2.04901523 * temperature +
10.14333127 * percentHumidity +
-0.22475541 * temperature * percentHumidity +
-0.00683783 * pow(temperature, 2) +
-0.05481717 * pow(percentHumidity, 2) +
0.00122874 * pow(temperature, 2) * percentHumidity +
0.00085282 * temperature * pow(percentHumidity, 2) +
-0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2);
if ((percentHumidity < 13) && (temperature >= 80.0) && (temperature <= 112.0))
hi -= ((13.0 - percentHumidity) * 0.25) * sqrt((17.0 - abs(temperature - 95.0)) * 0.05882);
else if ((percentHumidity > 85.0) && (temperature >= 80.0) && (temperature <= 87.0))
hi += ((percentHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2);
}
return hi;
}

3
cameras/README.md Normal file
View File

@ -0,0 +1,3 @@
# Cameras
Various configs for different cameras deployed on the network.

6
cameras/unifi_video.yaml Normal file
View File

@ -0,0 +1,6 @@
- platform: uvc
nvr: !secret unifi_video_nvr
port: !secret unifi_video_port
key: !secret unifi_video_api_key
password: !secret unifi_video_camera_password
ssl: true

View File

@ -1,228 +1,203 @@
# Enables Default Home Assistant Components
default_config:
# Enables Person Component
person:
# Enables System Health
system_health:
# Cameras
# @link https://home-assistant.io/components/camera/
#camera: !include_dir_merge_list cameras/
# Enable the configuration UI
# @link https://home-assistant.io/components/config/
config:
# Counters
# @link https://www.home-assistant.io/components/counter/
#counter: !include misc/counters.yaml
# Enable the UI customizer
# @link https://github.com/andrey-git/home-assistant-customizer
# customizer:
# custom_ui: local
# Device trackers
# @link https://home-assistant.io/components/device_tracker/
#device_tracker: !include misc/device_trackers.yaml
# Discover some devices automatically
# @link https://home-assistant.io/components/discovery/
discovery:
ignore:
- google_cast
# Displays
# @see /custom_components/display/
# @link https://github.com/daemondazz/homeassistant-displays
#display: !include misc/displays.yaml
# Enable the official UI
# @link https://home-assistant.io/components/frontend/
frontend:
# javascript_version: latest
# extra_html_url:
# - /local/custom_ui/state-card-custom-ui.html
# - /local/custom_ui/state-card-hline.html
# - /local/custom_ui/state-card-value_only.html
# extra_html_url_es5:
# - /local/custom_ui/state-card-custom-ui-es5.html
# - /local/custom_ui/state-card-hline.html
# - /local/custom_ui/state-card-value_only.html
# themes: !include_dir_named themes/
# Combine entities into groups and organize UI
# @link https://home-assistant.io/components/group/
#group: !include_dir_merge_named groups/
# Enable support for tracking state changes over time
# @link https://home-assistant.io/components/history/
history:
# Setup basic Home Assistant information
homeassistant:
name: !secret zone_home_name
latitude: !secret zone_home_latitude
longitude: !secret zone_home_longitude
elevation: !secret zone_home_elevation
unit_system: imperial # metric
time_zone: !secret homeassistant_time_zone
#customize_glob: !include customize_glob.yaml
#customize: !include customize.yaml
whitelist_external_dirs:
- !secret homeassistant_whitelist_config
# Enable the web server
# `cors_allowed_origins` includes the domain:port for AppDaemon.
# @link https://home-assistant.io/components/http/
http:
api_password: !secret http_password
base_url: !secret http_base_url
# Input booleans
# @link https://home-assistant.io/components/input_boolean/
#input_boolean: !include misc/input_booleans.yaml
# Lists of selectable values
# @link https://home-assistant.io/components/input_select/
#input_select: !include misc/input_selects.yaml
# LIFX
# @link https://www.home-assistant.io/components/lifx/
#lifx: !include misc/lifx.yaml
# Lights
# @link https://home-assistant.io/components/light/
#light: !include_dir_merge_list lights/
# View all events in a logbook
# @link https://home-assistant.io/components/logbook/
logbook:
# Log some details
# @link https://home-assistant.io/components/logger/
logger:
default: warning
# logs:
# aiohttp.server: critical # EBOX newer component bug.
# custom_components.display: critical # When tablet is offline.
# custom_components.light.lightpack: critical # When Lightpack is offline.
# homeassistant.components.device_tracker.unifi: fatal # When Unifi Controller is temporarily unreachable.
# homeassistant.components.media_player.plex: fatal # When Plex is offline.
# homeassistant.components.switch.tplink: error # When switch is unplugged.
# pyunifi.controller: error # When Unifi Controller is temporarily unreachable.
# Media players
# @link https://home-assistant.io/components/media_player/
#media_player: !include misc/media_players.yaml
# MQTT Integration
# @link https://home-assistant.io/components/mqtt/
#mqtt:
# broker: !secret mqtt_broker
# port: !secret mqtt_port
# username: !secret mqtt_username
# password: !secret mqtt_password
# birth_message:
# topic: 'hass/status'
# payload: 'online'
# will_message:
# topic: 'hass/status'
# payload: 'offline'
# Notification services
# @link https://home-assistant.io/components/notify/
#notify: !include_dir_merge_list notifications/
# Database recorder
# Limit the number of tracked entities and length of history.
# @link https://home-assistant.io/components/recorder/
#recorder: !include misc/recorder.yaml
recorder:
db_url: !secret recorder_db_url
purge_keep_days: 90
purge_interval: 1
# Scenes
# @link https://home-assistant.io/components/scene/
#scene: !include misc/scenes.yaml
# Scripts
# @link https://home-assistant.io/components/script/
#script: !include_dir_named scripts/
# Sensors
# @link https://home-assistant.io/components/sensor/
#sensor: !include_dir_merge_list sensors/
# Shell commands
# @link https://home-assistant.io/components/shell_command/
#shell_command: !include misc/shell_commands.yaml
# Track the sun
# @link https://home-assistant.io/components/sun/
sun:
# Switches
# @link https://home-assistant.io/components/switch/
#switch: !include_dir_merge_list switches/
# Check for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# Optionally allow Home Assistant developers to focus on popular components.
# @link https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
# @link https://home-assistant.io/components/updater/
updater:
include_used_components: true
# Variables
# @see /custom_components/variable.py
# @link https://github.com/rogro82/hass-variables
#variable: !include misc/variables.yaml
# Zones
# @link https://home-assistant.io/components/zone/
#zone: !include misc/zones.yaml
# ZWave integration
# @link https://home-assistant.io/docs/z-wave/adding/
# @link https://home-assistant.io/docs/z-wave/
# @link https://home-assistant.io/components/zwave/
#zwave:
# usb_path: /dev/ttyACM0
# network_key: !secret zwave_network_key
# Setup basic Home Assistant information
homeassistant:
name: !secret zone_home_name
latitude: !secret zone_home_latitude
longitude: !secret zone_home_longitude
elevation: !secret zone_home_elevation
unit_system: imperial # metric
time_zone: !secret homeassistant_time_zone
customize_domain: {}
customize_glob: {}
whitelist_external_dirs:
- !secret homeassistant_whitelist_config
# Database recorder
recorder:
db_url: !secret recorder_db_url
purge_keep_days: 90
purge_interval: 1
# Log some details
logger:
default: warning
logs:
homeassistant.components.device_tracker.unifi: fatal # When Unifi Controller is temporarily unreachable.
pyunifi.controller: error # When Unifi Controller is temporarily unreachable.
# Check for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# Optionally allow Home Assistant developers to focus on popular components.
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
# https://home-assistant.io/components/updater/
updater:
include_used_components: true
# MQTT Integration
# https://home-assistant.io/components/mqtt/
#mqtt:
# broker: !secret mqtt_broker
# port: !secret mqtt_port
# username: !secret mqtt_username
# password: !secret mqtt_password
# birth_message:
# topic: 'hass/status'
# payload: 'online'
# will_message:
# topic: 'hass/status'
# payload: 'offline'
# ZWave integration
# https://home-assistant.io/docs/z-wave/adding/
# https://home-assistant.io/docs/z-wave/
# https://home-assistant.io/components/zwave/
#zwave:
# usb_path: /dev/ttyACM0
# network_key: !secret zwave_network_key
# Enable the web server
# `cors_allowed_origins` includes the domain:port for AppDaemon.
# https://home-assistant.io/components/http/
http:
api_password: !secret http_password
base_url: !secret http_base_url
# Enable the official UI
# https://home-assistant.io/components/frontend/
frontend:
# javascript_version: latest
# extra_html_url:
# - /local/custom_ui/state-card-custom-ui.html
# - /local/custom_ui/state-card-hline.html
# - /local/custom_ui/state-card-value_only.html
# extra_html_url_es5:
# - /local/custom_ui/state-card-custom-ui-es5.html
# - /local/custom_ui/state-card-hline.html
# - /local/custom_ui/state-card-value_only.html
# themes: !include_dir_named themes/
# Enable the UI customizer
# https://github.com/andrey-git/home-assistant-customizer
#customizer:
# custom_ui: local
# Notification services
# https://home-assistant.io/components/notify/
#notify: !include_dir_merge_list notifications/
# Enables Default Home Assistant Components
default_config:
# Enables Person Component
person:
# Combine entities into groups and organize UI
# https://home-assistant.io/components/group/
#group: !include_dir_merge_named groups/
# Zones
# https://home-assistant.io/components/zone/
#zone: !include misc/zones.yaml
# Variables
# @see /custom_components/variable.py
# https://github.com/rogro82/hass-variables
#variable: !include misc/variables.yaml
# Counters
# https://www.home-assistant.io/components/counter/
#counter: !include misc/counters.yaml
# Input booleans
# https://home-assistant.io/components/input_boolean/
#input_boolean: !include misc/input_booleans.yaml
# Lists of selectable values
# https://home-assistant.io/components/input_select/
#input_select: !include misc/input_selects.yaml
# Enables System Health
system_health:
# Enable the configuration UI
config:
# Enable support for tracking state changes over time
history:
# View all events in a logbook
logbook:
exclude:
entities:
- sensor.uptime
- sensor.time
- sensor.date
- sensor.date_time
- sensor.date_time_iso
- sensor.time_date
- sensor.time_utc
- sensor.beat
- sensor.pcf8523
# Scenes
# https://home-assistant.io/components/scene/
#scene: !include misc/scenes.yaml
# Discover some devices automatically
discovery:
ignore:
- google_cast
- harmony
# Device Trackers
device_tracker: !include_dir_merge_list device_trackers/
# Cameras
camera: !include_dir_merge_list cameras/
# Displays
# @see /custom_components/display/
# https://github.com/daemondazz/homeassistant-displays
#display: !include misc/displays.yaml
# Sensors
sensor: !include_dir_merge_list sensors/
# Track the sun
sun:
# Cameras
# https://home-assistant.io/components/camera/
#camera: !include_dir_merge_list cameras/
# Media Devices
cast: !include media/cast.yaml

View File

@ -0,0 +1,3 @@
# Device Trackers
Various configs for tracking devices.

View File

@ -0,0 +1,25 @@
- platform: unifi
host: !secret unifi_host
port: !secret unifi_port
username: !secret unifi_username
password: !secret unifi_password
ssid_filter:
!secret unifi_ssids
monitored_conditions:
- _id
- assoc_time
- authorized
- bssid
- channel
- essid
- first_seen
- hostname
- ip
- last_seen
- latest_assoc_time
- mac
- name
- signal
- site_id
- user_id
- usergroup_id

3
docker/README.md Normal file
View File

@ -0,0 +1,3 @@
# Docker
Various run scripts for deploying Home-Automation.io on arm boards. Raspberry Pi and others are supported.

View File

@ -4,6 +4,10 @@
# create role homeautomation nosuperuser nocreatedb nocreaterole password 'badPassword';
# create database homeautomation owner homeautomation;
# --device /dev/ttyACM0:/dev/ttyACM0
# --device /dev/rtc1:/dev/rtc1
# -v /sys/class:/sys/class
ARCH=`arch`
if [ $ARCH == "aarch64" ]
then
@ -12,16 +16,20 @@ else
REPO="homeassistant/raspberrypi3-homeassistant"
fi
touch /var/home-assistant/known_devices.yaml
docker container stop home-assistant
docker container rm home-assistant
docker run -it --name home-assistant \
--restart unless-stopped \
--network docker-private \
--device /dev/ttyACM0:/dev/ttyACM0 \
-e DEBUG=1 \
-l traefik.frontend.rule=Host:home-automation.domain.tld \
-l traefik.frontend.passHostHeader=true \
-l traefik.port=8123 \
-v /sys/class:/sys/class \
-v /etc/localtime:/etc/localtime:ro \
-v /var/home-assistant:/config \
${REPO}:latest

View File

@ -1,18 +1,9 @@
## Home-Automation.io
- https://www.home-assistant.io/components/recorder/
- https://www.home-assistant.io/
- https://www.home-assistant.io/docs/installation/docker/
- https://www.home-assistant.io/docs/ecosystem/backup/backup_usb/
- https://www.home-assistant.io/docs/z-wave/
- https://www.home-assistant.io/docs/z-wave/installation
- https://www.home-assistant.io/docs/z-wave/adding
- https://community.home-assistant.io/t/real-time-clock/91699
- https://www.home-assistant.io/components/time_date/
- https://www.home-assistant.io/components/worldclock/
- https://www.home-assistant.io/components/timer/
- https://www.home-assistant.io/components/persistent_notification/
- https://community.home-assistant.io/t/medication-reminder/18110
@ -20,53 +11,20 @@
- https://github.com/pkozul/ha-floorplan
- https://github.com/thomasloven/hass-fontawesome
- https://www.home-assistant.io/components/caldav/
- https://www.home-assistant.io/components/weather.darksky/
- https://www.home-assistant.io/components/cloudflare/
- https://www.home-assistant.io/components/command_line/
- https://www.home-assistant.io/components/darksky/
- http://davmail.sourceforge.net/
- https://www.home-assistant.io/components/generic/
- https://www.home-assistant.io/components/input_datetime/
- https://www.home-assistant.io/components/input_boolean/
- https://www.home-assistant.io/components/input_select/
- https://www.home-assistant.io/components/linux_battery/
- https://www.home-assistant.io/components/logbook/
- https://www.home-assistant.io/components/matrix/
- https://www.home-assistant.io/components/miflora/
- https://www.home-assistant.io/components/nfandroidtv/
- https://www.home-assistant.io/components/plant/
- https://www.home-assistant.io/components/pollen/
- https://www.home-assistant.io/components/smtp/
- https://www.home-assistant.io/components/uvc/
- https://www.home-assistant.io/components/unifi/
- https://www.home-assistant.io/components/ups/
- https://www.home-assistant.io/components/fedex/
- https://www.home-assistant.io/components/usps/
### Samples
- https://github.com/renemarc/home-assistant-config/
- https://github.com/stanvx/Home-Assistant-Configuration
- https://www.awesome-ha.com/
## Simple Sensor Array
- https://learn.sparkfun.com/tutorials/arduino-weather-shield-hookup-guide-v12
- http://pinoutguide.com/images/arduino/micro.png
- https://strawberry-linux.com/pub/Weather%20Shield.pdf
- https://cdn.sparkfun.com/assets/1/1/4/d/6/Weather_Shield_V12.pdf
- https://www.arduino.cc/en/main/software#download
- https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino
- https://github.com/sparkfun/Weather_Shield
https://www.home-assistant.io/components/serial/
Humidity = 45.52%, temp_h = 22.58C, Pressure = 99065.00Pa, temp_p = 71.37F, light_lvl = 4.20V, VinPin = 0.00V
## Networked Devices
- https://www.home-assistant.io/components/harmony/
- https://www.home-assistant.io/components/cast/
## Setup Kiosk For HASS

View File

@ -1,16 +1,37 @@
#
# Home Assistant basic info
#
zone_home_name: "Some Name"
zone_home_latitude: 0.0
zone_home_longitude: 0.0
zone_home_elevation: 0.0
zip_code: "00544"
homeassistant_time_zone: America/Eastern
homeassistant_whitelist_config: ./
http_base_url: ""
http_password: ""
#
# Database Setup
#
recorder_db_url: "postgresql://user:password@SERVER_IP/DB_NAME"
# API Keys
dark_sky_api_key: YOUR_API_KEY_HERE
# Media Devices
google_casts:
- host: 172.16.0.1
- host: 10.0.0.1
- host: 192.168.0.1
# UniFi Config
unifi_host: unifi.domain.tld
unifi_port: 8443
unifi_username: username
unifi_password: password
unifi_ssids:
- ssid_1
- ssid_2
# UniFi Video Config
unifi_video_nvr: unifivideo.domain.tld
unifi_video_port: 7080
unifi_video_api_key: API_KEY
unifi_video_camera_password: ubnt

3
sensors/README.md Normal file
View File

@ -0,0 +1,3 @@
# Sensors
Various sensor configurations. Each of the ```yaml``` files is a *different* sensor.

14
sensors/pollen.yaml Normal file
View File

@ -0,0 +1,14 @@
- platform: pollen
zip_code: !secret zip_code
monitored_conditions:
- allergy_average_forecasted
- allergy_average_historical
- allergy_index_today
- allergy_index_tomorrow
- allergy_index_yesterday
- asthma_average_forecasted
- asthma_average_historical
- asthma_index_today
- asthma_index_tomorrow
- asthma_index_yesterday
- disease_average_forecasted

4
sensors/rtc1.yaml Normal file
View File

@ -0,0 +1,4 @@
- platform: command_line
name: "pcf8523"
command: 'hwclock -r -f /dev/rtc1'
scan_interval: 3600

View File

@ -0,0 +1,3 @@
# Sensor Scripts
A collection of scripts for building more robust command line sensors to fill in gaps in the upstream components.

35
sensors/scripts/ac_sopine.py Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env python3
from distutils.util import strtobool
PATH_PRESENT = '/sys/class/power_supply/axp813-ac/present'
PATH_ONLINE = '/sys/class/power_supply/axp813-ac/online'
PATH_TYPE = '/sys/class/power_supply/axp813-ac/type'
PATH_HEALTH = '/sys/class/power_supply/axp813-ac/health'
PATH_INPUT_CURRENT_LIMIT = '/sys/class/power_supply/axp813-ac/input_current_limit'
PATH_VOLTAGE_MIN = '/sys/class/power_supply/axp813-ac/voltage_min'
present = False
with open(PATH_PRESENT, 'r') as f:
present = bool(strtobool(f.read().strip()))
online = False
with open(PATH_ONLINE, 'r') as f:
online = bool(strtobool(f.read().strip()))
result = {'present': present, 'online': online}
if present:
with open(PATH_TYPE, 'r') as f:
result['type'] = f.read().strip()
with open(PATH_HEALTH,'r') as f:
result['health'] = f.read().strip()
with open(PATH_INPUT_CURRENT_LIMIT, 'r') as f:
current = f.read().strip()
result['current'] = (int(current)/10000.0)*0.01
with open(PATH_VOLTAGE_MIN, 'r') as f:
voltage = f.read().strip()
result['voltage'] = (int(voltage)/10000.0)*0.01
import json
print(json.dumps(result))

View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
from distutils.util import strtobool
PATH_PRESENT = '/sys/class/power_supply/axp20x-battery/present'
PATH_STATUS = '/sys/class/power_supply/axp20x-battery/status'
PATH_VOLTAGE = '/sys/class/power_supply/axp20x-battery/voltage_now'
PATH_CURRENT = '/sys/class/power_supply/axp20x-battery/current_now'
PATH_CAPACITY = '/sys/class/power_supply/axp20x-battery/capacity'
PATH_HEALTH = '/sys/class/power_supply/axp20x-battery/health'
present = False
with open(PATH_PRESENT, 'r') as f:
present = bool(strtobool(f.read().strip()))
result = {'present': present}
if present:
with open(PATH_STATUS,'r') as f:
result['status'] = f.read().strip()
with open(PATH_VOLTAGE, 'r') as f:
voltage = f.read().strip()
result['voltage'] = (int(voltage)/10000.0)*0.01
with open(PATH_CURRENT, 'r') as f:
current = f.read().strip()
result['current'] = int(current)/1000
with open(PATH_CAPACITY, 'r') as f:
result['capacity'] = f.read().strip()
with open(PATH_HEALTH, 'r') as f:
result['health'] = f.read().strip()
import json
print(json.dumps(result))

32
sensors/sopine-ac.yaml Normal file
View File

@ -0,0 +1,32 @@
- platform: command_line
name: "sopine_ac"
command: '/config/sensors/scripts/ac_sopine.py'
json_attributes:
- present
- voltage
- online
- health
- type
- current
- platform: template
sensors:
sopine_ac_present:
entity_id: "sensor.sopine_ac"
value_template: "{{ state_attr('sensor.sopine_ac', 'present') }}"
sopine_ac_voltage:
entity_id: "sensor.sopine_ac"
value_template: "{{ state_attr('sensor.sopine_ac', 'voltage') }}"
sopine_ac_online:
entity_id: "sensor.sopine_ac"
value_template: "{{ state_attr('sensor.sopine_ac', 'online') }}"
sopine_ac_health:
entity_id: "sensor.sopine_ac"
value_template: "{{ state_attr('sensor.sopine_ac', 'health') }}"
sopine_ac_type:
entity_id: "sensor.sopine_ac"
value_template: "{{ state_attr('sensor.sopine_ac', 'type') }}"
sopine_ac_current:
entity_id: "sensor.sopine_ac"
value_template: "{{ state_attr('sensor.sopine_ac', 'current') }}"

View File

@ -0,0 +1,34 @@
- platform: command_line
name: "sopine_battery"
command: '/config/sensors/scripts/battery_sopine.py'
json_attributes:
- status
- voltage
- capacity
- present
- current
- health
- platform: template
sensors:
sopine_battery_status:
entity_id: "sensor.sopine_battery"
value_template: "{{ state_attr('sensor.sopine_battery', 'status') }}"
sopine_battery_voltage:
entity_id: "sensor.sopine_battery"
value_template: "{{ state_attr('sensor.sopine_battery', 'voltage') }}"
unit_of_measurement: "V"
sopine_battery_capacity:
entity_id: "sensor.sopine_battery"
value_template: "{{ state_attr('sensor.sopine_battery', 'capacity') }}"
unit_of_measurement: "%"
sopine_battery_present:
entity_id: "sensor.sopine_battery"
value_template: "{{ state_attr('sensor.sopine_battery', 'present') }}"
sopine_battery_current:
entity_id: "sensor.sopine_battery"
value_template: "{{ state_attr('sensor.sopine_battery', 'current') }}"
unit_of_measurement: "A"
sopine_battery_health:
entity_id: "sensor.sopine_battery"
value_template: "{{ state_attr('sensor.sopine_battery', 'health') }}"

View File

@ -0,0 +1,49 @@
# {
# "humidity_percent":45.0025,
# "temp_c":23.00256,
# "pressure_pa":98949.5,
# "temp_f":72.1625,
# "hi_f":71.19387,
# "hi_c":21.77415,
# "light_lvl_v":0.106452,
# "batt_lvl_v":0
#}
- platform: serial
serial_port: /dev/ttyACM0
name: sparkfun_weather_station
- platform: template
sensors:
sparkfun_weather_station_humidity_percent:
entity_id: "sensor.sparkfun_weather_station"
value_template: "{{ state_attr('sensor.sparkfun_weather_station', 'humidity_percent') }}"
unit_of_measurement: "%"
sparkfun_weather_station_temp_c:
entity_id: "sensor.sparkfun_weather_station"
value_template: "{{ state_attr('sensor.sparkfun_weather_station', 'temp_c') }}"
unit_of_measurement: "C"
sparkfun_weather_station_pressure_pa:
entity_id: "sensor.sparkfun_weather_station"
value_template: "{{ state_attr('sensor.sparkfun_weather_station', 'pressure_pa') }}"
unit_of_measurement: "Pa"
sparkfun_weather_station_temp_f:
entity_id: "sensor.sparkfun_weather_station"
value_template: "{{ state_attr('sensor.sparkfun_weather_station', 'temp_f') }}"
unit_of_measurement: "F"
sparkfun_weather_station_hi_f:
entity_id: "sensor.sparkfun_weather_station"
value_template: "{{ state_attr('sensor.sparkfun_weather_station', 'hi_f') }}"
unit_of_measurement: "F"
sparkfun_weather_station_hi_c:
entity_id: "sensor.sparkfun_weather_station"
value_template: "{{ state_attr('sensor.sparkfun_weather_station', 'hi_c') }}"
unit_of_measurement: "C"
sparkfun_weather_station_light_lvl_v:
entity_id: "sensor.sparkfun_weather_station"
value_template: "{{ state_attr('sensor.sparkfun_weather_station', 'light_lvl_v') }}"
unit_of_measurement: "V"
sparkfun_weather_station_batt_lvl_v:
entity_id: "sensor.sparkfun_weather_station"
value_template: "{{ state_attr('sensor.sparkfun_weather_station', 'batt_lvl_v') }}"
unit_of_measurement: "V"

9
sensors/time.yaml Normal file
View File

@ -0,0 +1,9 @@
# Track various times
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_iso'
- 'time_date'
- 'time_utc'

45
sensors/weather.yaml Normal file
View File

@ -0,0 +1,45 @@
- platform: darksky
api_key: !secret dark_sky_api_key
forecast:
- 0
- 1
- 2
- 3
- 4
- 5
hourly_forecast:
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
monitored_conditions:
- summary
- icon
- temperature
- apparent_temperature
- temperature_high
- temperature_low
- humidity
- precip_type
- precip_intensity
- precip_probability
- precip_accumulation
- wind_speed
- wind_gust
- daily_summary
scan_interval:
# At least one of these must be specified:
days: 0
hours: 0
minutes: 30
seconds: 0
milliseconds: 0