Showing posts with label Home Assistant. Show all posts
Showing posts with label Home Assistant. Show all posts

Saturday, 21 September 2024

Home Automation


 I've been playing/researching/getting up to speed on Home Automation.


This consists so far, of Home Assistant running on a Raspberry PI 4, with a separate RPI Pico W running some sensors, communicating via MQTT to the HA instance, some BLE temperature/humidity sensors, some energy monitoring smart plugs & a couple of Shelly EM energy monitors flashed with Tasmota, monitoring energy.


It started off with a wish to monitor temperatures & humidity in the house & the loft, if only as a way to see how the loft insulation is doing & to tweak the radiator thermostatic valves.

The sensors are 

ThermoPro TP357

 https://www.amazon.co.uk/gp/product/B0BTSW9JGT/ref=ppx_od_dt_b_asin_title_s00?ie=UTF8&th=1

Battery powered, with a battery life of about a year, BLE Bluetooth low energy, they have the very  occasional spasm of odd readings, probably to do with the randomised nature of low energy Bluetooth .

Picked up as an integration in HA.

Raspberry PI4, with a case & power supply & a micro SD card. Home assistant added as an OS image to the card, insert in the RPI & boot, takes about 30mins.

https://www.home-assistant.io/installation/raspberrypi/


Use a network cable to start, but can be configured for Wi-Fi afterwards.


Lots to learn & configure, but can be used as is, the programming language YAML is a bit of a pain.

Having said that, I'm more comfortable with a soldering iron & test equipment, I think my last programming was 'Hello World' on a Sinclair ZX81! 

Update.

After a crash of home assistant, discovered the SD had failed, looks like not happy with constant writes.

Copied the OS image to an SSD with a usb adapter, applied the backup & all is well.

Moved the RPi sensors over to an ESP32 running a tweaked tasmota to accommodate the sensors,

I got fed up of the RPI W falling off wifi & MQTT & not reconnecting, I think the RPI MQTT implementation leaves a lot to be desired.

I use one of these https://thepihut.com/products/adafruit-veml7700-lux-sensor-i2c-light-sensor-ada4162 to sense the dim on led on the boiler, threshold is 2Lux!

As the boiler is the only gas appliance we have, I can use a  counter within HA to measure the daily, weekly, monthly on time of the boiler, albeit in 30sec steps, multiply this by a constant gives me the surprisingly accurate gas consumption without having to read the gas meter. & I can graph it over time.! 



Tasmota Shelly EM

 I acquired a couple of these https://shellystore.co.uk/product/shelly-em-50a/  with extra clamps.

They are easy to setup & fairly well calibrated, I compared them against the supply meter for a few days.

But, They only provide Energy usage rather than Voltage, Current, Power factor etc, so I decided to flash them with Tasmota. https://tasmota.github.io/docs/

One of these makes it easy, a tasmotizer pcb, with a 3.3V supply onboard, runs from a USB C port on a PC, https://www.amazon.co.uk/dp/B0C15K9ZC4/ref=pe_27063361_487055811_TE_dp_2, designed & produced by RevK https://www.revk.uk/ & used with Tasmotizer software https://github.com/tasmota/tasmotizer


THESE SHOULD ONLY BE CONNECTED WHEN THE EM IS NOT CONNECTED TO MAINS POWER, DAMAGE & A SHOCK HAZARD EXISTS!

1st thing was discovering the smaller pin header has 7 pins, & the Shelly EM has only 6 sockets, easy enough to cut off the 7th, unused pin, the other end from the ground pin.

2nd, after a couple of tries, was discovering several flavours of Tasmota, the one for the EM is the 4M flash version.



Smart Plugs Tasmota

 I bought some of these, https://www.mylocalbytes.com/products/smart-plug-pm, preflashed with Tasmota, also available with ESPhome & EU style sockets, not bad at £12.50 each, they will switch 13A.


Setup straightforward, usual WiFI Hub & MQTT broker details.


They are discovered by Home Assistant, so easy to set up.



Tuesday, 17 September 2024

Bluetooth Proxy

 I have a number of these,

https://buythermopro.com/product/tp357/?srsltid=AfmBOopPAqMD8LevxJewN2nf1H35xTTa1SQUm3UZew3Ek0fzLAU5LL80

Available from Amazon.


They are cheap, reasonably accurate, BLE thermometers & humidity sensors.


They are hooked up to Home Assistant via a Thermopro integration & work well, but the odd one is right on the edge of range from the RPI4 running HA.


So, never played with ESPHome before, it integrates into Home Assistant  & offers an easy way to compile & run on an ESP32.


I had a few spare ESP32C3 boards, so decided to give it a go.

Installed the ESPHome addon into HA, plugged the C3 board into my laptop, added a Bluetooth proxy & compiled it, it compiles on the RPI4 & makes it stagger a bit, despite having several  goes at installing it, it baulks at the installation.


I used a downloaded ESP installer which works, after that all updates are done over wifi.


Sat & watched it, no devices showing in the log, tweaked to log to verbose, still nothing.


Edited the YAML to try various things, nothing.


Eventually, this works,


esphome:
  name: bluetooth-proxy
  friendly_name: Bluetooth Proxy

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y
      CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y
      CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10"

esp32_ble_tracker:
  scan_parameters:
# Adjust timing if the defaults do not work in your environment
#    interval: 1100ms
#    window: 1100ms
    active: true

bluetooth_proxy:
  active: true
 

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxx"

ota:
  - platform: esphome
    password: "xxxxxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Bluetooth-Proxy Fallback Hotspot"
    password: "xxxxxxxxxxxxx"

captive_portal:
   

It proxies the Bluetooth packets over wifi to whatever integration requires it (in my case Thermopro)
It runs seamlessly with the normal Bluetooth on the RPI4.

Result!