RLP's Personal Blog

Bearded Dragon Automation

Article Info

Recent Changes

About


We have a female bearded dragon named Waffles. Bearded Dragons, it turns out, do better within a fairly tight temperature range that is NOT the range natural to San Francisco. There are various methods to handle this, including mechanical temperature-sensing timers of various kinds.

Me, I have 3 smart home temperature and humidity sensors in her cage, and 3 smart home plugs to control her lights (UV, ceramic heat (no light), and basking bulb). I use Node Red to manage them, and a combination of Node Red and InfluxDB to graph their history.

That’s normal, right? That’s what normal people do? Yeah. Of course.

Anyway, these are notes to myself to help me remember what I did and why.

Web Interface

Main hassio interface has Node Red and the graphs.

Host & Access

The hassio host is a KVM running on lebna; https://github.com/rlpowell/hassio-vm is checked out in /srv/hassio

To access the host itself:

$ ssh hassio

Currently only the rlpowell account is there.

From there, docker commands work as usual, such as:

$ sudo docker exec -it addon_a0d7b954_nodered bash

The hassio VM mounts /srv/hassio/data-hassio and /srv/hassio/data-influxdb

influxdb is used to store time series data (i.e. the temperatures). It runs in the KVM just because we’ve installed influx-db, using the data mounted from /srv/hassio/data-influxdb

To manage influx, ssh to rlpowell@hassio and run “influx”. Some influx commands:

# Show all measurements
$ use waffles_sensors
$ select count(*) from /./
# What the graphs do
$ select mean(value) as value from /humidity/ where time > (now() - 7d) group by time(5m)

Why Is The Day Bulb Always On?

As of 4 Apr 2021, it appears that under normal SF conditions the day bulb cannot, by itself, push the temp above the mid 90s, so current automation has it on always during the day unless the temp is dangerously high; this may need revisiting.

New Temp Setup

30 Mar 2021: Working on a new temperature setup, as the old one, which just had “day” and “night”, was causing problems.

(Note: all values in degrees Fahrenheit.)

The basic goal here is to smooth things out, so: here’s a graph.

(I may not end up using exactly those numbers, but you get the idea.)

How this works: there are a multiple of 360 minutes in the day (4x360, to be exact), so “x” in this function is “number of minutes in the day so far / 4”, which gives a number from 0 to 360, i.e. degrees. Multiply by pi/180 to get radians. +1.5pi to shift it so that 1 unit of the sine wave starts and ends at the 0 value. This means that midnight, and just before and just after midnight, are the -1 value, and noon is the +1 value. Then multiply and add to shift it from “-1 to +1” to “70 to 100”.

This gives us the target temp.

We then simplify the situation dramatically by only using that temp as the hot side temp (i.e. the basking surface temp), and ignoring all other temps, except for alarming.

We then try to stay near that temp. This is easy: if the hot side is 1 degree (or more) below the target, we turn the heating element on; if the hot side is 1 degree (or more) above, we turn the heating element off. The degree on either side is to prevent switching the light on and off every 30 seconds, and might be too narrow a range.

During the day, the heating element is the basking bulb. During the night, it’s the ceramic heat emitter.

Because the goal is to never have extreme temperature shifts needed, we never turn on both heating elements.

(Side note: this means that we should unconditionally turn off the other heating element on every pass.)

Now, alarming is for when temperatures go badly out of whack, but knowing what that means seems complicated; in particular, during the day the temp range between the cold and hot side of the enclosure is about 20oF, and at night it’s more like 2oF; this is a big difference for what “out of whack” can mean.

We can simplify this dramatically, though, by simply asserting that we don’t care very much how wacky the temps get as long as they’re within a safe range for a bearded dragon.

This isn’t true, of course; we do care. But alarming is for when things have gone badly out of whack.

So: we alarm unconditionally when any temp is above 110oF or below 60oF, which is 10oF above and below our max and min targets for the entire day. We alarm when the hot side (which is what we’re tracking) gets more than 20oF away from the target. And we alarm when the cold side is above 90oF (which we might need to revise during the summer).

Honestly, the “correct” thing here is to have another temperature sensor outside the cage to make more complex decisions with, but this should be good enough.