Home Assistant: Extracting Data from a JSON (ish) MQTT Payload using Value Template

So you’ve got a device pushing MQTT messages. If you do the bare minimum configuration,

mqtt:
  sensor:
    - name: "Pico W Air"
      state_topic: "enviro/picowair"

you get an entity in Home Assistant that gives you something like this:

{"pm100 env": 1, "particles 03um": 224, "pm100 standard": 1, "particles 25um": 0, "pm25 standard": 1, "pm10 env": 0, "pm10 standard": 0, "pm25 env": 1, "particles 05um": 62, "particles 10um": 14, "particles 100um": 0, "particles 50um": 0}

This does not give you anything that you can actually use. Add this below state_topic:

      value_template: "{{ (value|from_json)['particles 03um'] }}"

This now returns an actual value that you can work with. In this case it would return 224.

I got stock on value_json for a long time, which as far as I can tell should let you just specify the “field” you want and return the data. Evidently this would work if the data was in quotes.

https://community.home-assistant.io/t/template-variable-error-value-json-is-undefined-mqtt/388902/20

Resetting Home Assistant Utility Meters Manually

Developer tools > Services > Utility Meter: Calibrate

I would imagine there is a way to get this into a button, but have no idea how to do that.

This is useful for things like tracking air purifier run times, where you don’t want the meter reset until you actually change the filter. For most things, automatic reset based on a time period is probably fine.

Source: https://community.home-assistant.io/t/manual-reset-utility-meter/320665/5

Tracking Stuff Over Time in Home Assistant (Utility Meters, Reimann Sum, History Stats)

To track something over time, you need a sensor that outputs a unit of something over time (kilowatt-hours), outputs a state that you can track (on), or outputs instantaneous usage (watts).

The simplest example is tracking electricity usage. Most smart plugs will output instantaneous usage in watts, while some will give a total of kilowatt-hours. If you have a device that does the latter, you can simply create a utility meter from the sensor.

If your device only outputs instantaneous usage, use a Reimann sum helper to get usage over time. Then create a utility meter from the helper.

The most complicate situation is when you need to track something’s state over time. For example, getting total runtime of an air purifier to know when to change its filter. In this situation, you need something that will provide an on/off state (usually the device itself, but you could also create your own helper sensor). Then create a history_stats sensor, then create a utility meter from that.

Here’s my example, which is largely copied-and-pasted from the Home Assistant documentation:

sensor:
  - platform: history_stats
    name: Bedroom Air Purifier On History
    entity_id: binary_sensor.bedroom_air_purifier_on_off
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

This says look at the helper sensor I created to determine when the air purifier is on, and then track how much time it is on.

When doing anything involving utility meters from within the UI (or maybe especially when doing it using the UI), reload Home Assistant. There can be some weird behaviors if you don’t.

The Home Assistant Syncthing integration failed to connect

If you’ve entered in the IP address and the API key but the integration doesn’t connect, that’s because by default Syncthing is only accessible from the local machine. You have to change the GUI listen address to 0.0.0.0 from 127.0.0.1.

Source:

https://community.home-assistant.io/t/how-to-integrate-your-syncthing-and-even-make-it-talk/209116

Starfield: How to Build a Greenhouse / Animal Husbandry Facility

The game is needlessly obtuse, so here’s what you need to do:

  • At least 1 point in Botany/Zoology
  • At least 1 point in Outpost Engineering
  • Complete the relevant research to unlock the building (e.g. Horticulture 1)
  • You need to scan the plant/animal to 100% after unlocking the building. If you scanned and then unlocked, the building probably won’t appear. Go around and scan again.

The greenhouse in particular does not function as you would assume from the name – you can’t grow apples on the Moon, for example. Each plant grows in one or more biomes on a specific planet. You must place the greenhouse in one of those biomes on that planet to then grow the plant and produce the corresponding material.

Update 11/22/23: while plants are found in specific biomes (meaning you must go to the biome to scan them), it appears that growing them in a greenhouse only requires that you place the greenhouse somewhere on the planet.

Greenhouses must be supplied with water, either using an extractor (no specific resource patch required) or a moisture vaporator (or whatever the game calls it).

Using the Qingping Air Monitor Lite with Home Assistant

I’ve been putting this one off for a long time because from my research it seemed like there were several different methods for getting this to work.

Qingping Integration

There is a Home Assistant Qingping integration. This really didn’t do anything at first, with the Air Monitor having been previously set up via the iOS Qingping app and HomeKit. Home Assistant saw the device, but wasn’t getting any data.

It did start working after I set up the Air Monitor with the Mi Home app (Android), which involved resetting the Air Monitor. This requires that you set up a Xiaomi/Mi Home account and set your account region to China. If you use the US region, the Air Monitor is not available to set up.

This integration gives you the PM2.5/PM10, CO2, humidity, and temperature readings. It seems like it works locally? The issue is that the Air Monitor has already been set up with a Xiaomi account and presumably you would have to block internet access on your router to stop any further data transmission.

Xiaomi Miot for Home Assistant

This is a Home Assistant Community Store integration found on Github. The documentation says it supports local operation for certain devices but the Air Monitor Lite does not appear to be one of them. Compared to the Qingping integration, this additionally provides battery voltage and charge status data.

Install HACS and then install this integration. From the normal integration menu, add Xiaomi Miot Auto. From here you can either enter your Xiaomi account information or use an access token. I used the Get Mi Home Devices Token app. Since you’re entering your login info into software you don’t necessarily trust, I don’t know that one option is any better than the other. Setting up the Air Monitor via the second method involves providing an IP address, so I set that as static just in case.

Why the Qingping Air Monitor Lite in the first place?

At the time, maybe spring/summer 2022, it was one of the only cheap (~$100) CO2/PM2.5/PM10 air quality monitors that you didn’t have to DIY. I had a “smart” air purifier with built-in sensors that I didn’t really trust (it died later, which apparently is quite common) and wanted a separate unit. I just didn’t want to spend $250 on the Aranet4, though I eventually got one on sale.

The CO2 readings are low compared to the Aranet, but it does generally trend in the same direction. Unfortunately I don’t have anything to compare the particle readings to, but it spikes when you’d expect it to spike (wildfire smoke or frying/roasting).

I have found the battery-powered functionality useful when I’ve taken it in the car or to the office. The Qingping app is not good–it asks for login information constantly. You don’t have to register to use it, but it will keep asking. There are some issues with the Air Monitor storing settings, but with enough persistence it will eventually work.

Disassembling the Glorious Model O Wireless Mouse

  1. Remove the rear skates and unscrew 2 screws. You probably won’t be able to re-use the skates.
  2. The top shell of the mouse is mostly clipped in. Comes apart fairly easily, but mind the cables.
  3. The top PCB is attached with 1 screw and 1 clip. The battery is glued in place within some foam that tore apart.
  4. The bottom PCB is attached with 2 screws.

Multiple Cameras with the new camera stack (camera-streamer) in OctoPrint

  1. Install the appropriate image (first part of the instructions found here).
  2. In my case, I had a working Pi Cam and then wanted to add a USB cam, so the instructions for adding multiple cameras found further down the page worked just fine. Pay attention to the port number that is given. Should be 8081 for the first additional camera.
  3. At this point, you can see the feed for the first camera at http://ip_address/webcam/?action=stream, but the second camera feed is nowhere to be found.
  4. The answer lies in this post. You need to modify the conf file for the second camera (found in /etc/camera-streamer.conf.d/). The options section should look like OPTIONS="--http-listen=0.0.0.0".
  5. Reboot the Pi, probably. The second camera will now be accessible at http://ip_address:8081/webcam/?action=stream.
  6. From here, you can do something like set up MultiCam, which will allow you to toggle between/among cameras in the web interface.

I’ve tested (briefly) the following apps/services and as of now the behavior is as follows:

  • OctoPod (iOS) – uses the second camera; unclear what mechanism is used to select cameras. There does not appear to be multi-camera support.
  • OctoApp (iOS/Android) – uses the first camera; does not appear to have multi-camera support.
  • Obico – uses the first camera; does not appear to have multi-camera support. They do however have a nozzle-cam feature which seemingly works with the nozzle-cam set up as a secondary camera.