Weather Data Camera Overlay (axis cameras): How To!

Ever wanted to put weather data (or really any other data) into an overlay on a camera, like this?:

Here’s how you can do it. It takes three parts: a shell script, a command line handler, and an automation. This example is specifically for how to do this with axis brand cameras, since they have that handy vapix api.

First, create a shellscript that will do the heavy lifting for you. Here’s mine:

#!/bin/bash

#take input args for data
max_gust=$1
temp=$2
wind_speed=$3

# if HA isnt booted yet, lets not put 'unavailable' on the cam overlay
if [ "$max_gust" = "unavailable" ] || [ "$temp" = "unavailable" ] || [ "$wind_speed" = "unavailable" ]; then
    exit 1
fi

# Construct overlay text
overlay_text="Max Gust: $max_gust, Temp: $temp f, Wind Speed: $wind_speed"

# My camera takes digest auth, yours may do basic auth. please take note.
# also make sure to note the overlay ID. I only have two on my camera, you may have more
camera_user="username"
camera_pass="password"
overlay_id="2" 

# Axis camera API endpoint
api_endpoint="http://0.0.0.0/axis-cgi/dynamicoverlay/dynamicoverlay.cgi"

curl -s --digest -u "$camera_user:$camera_pass" \
     -X POST \
     -H "Content-Type: application/json" \
     --data '{"apiVersion": "1.0", "method": "setText", "params": {"identity":'"$overlay_id"',"text":"'"$overlay_text"'"}}' \
     "$api_endpoint" 2>&1 > /dev/null

The shellscript is pretty straightforward. It just takes user input and then constructs a json http post to fling at the camera. My camera uses digest auth (any cams updated within the last like 2 years will), yours may do basic auth, so if thats the case you’ll have to re-jigger the shellscript for that.

Next, drop the shellscript somewhere. I put mine in /root/config, which is the dir that HA runs stuff out of, making the next part much easier.

After that, edit your configuration.yaml and add a shell command stanza.

shell_command:
  cam_weather: bash cam_weather.sh "{{max_gust}}" "{{temp}}" "{{wind_speed}}"

HA will need to be bounced at this point so that the system can recognize your new shell_command. Once you’ve restarted HA, you can build the automation:

alias: Camera Weather Data Overlay
description: Updates camera overlay with weather data
trigger:
  - platform: time_pattern
    seconds: /30
action:
  - service: shell_command.cam_weather
    data:
      max_gust: "{{ states('sensor.your_sensor_here') }}"
      temp: "{{ states('sensor.your_sensor_here') }}"
      wind_speed: "{{ states('sensor.your_sensor_here') }}"

This automation runs every thirty seconds, and takes three sensors from my ambient weather station and plumbs them into the command line, feeding it to the shellscript.

make sure the shell_command arguments and the automation arguments are in matching order If you mix them up you’ll mix up the values as they appear in the camera.

That’s it!
You can also use this plumbing to basically put literally any data you can get out of HA into an axis camera. Just make sure you know what the ID number of your text overlay is. For me it was easy because I only had one in there to begin with (the timestamp), so adding a second was straightforward - but go nuts! Do cool stuff and post pics of it here!

3 Likes