Skip to content

Instantly share code, notes, and snippets.

@toshinarin
Last active June 21, 2020 00:50
Show Gist options
  • Save toshinarin/443698dda38f5e57da0d4554348b8798 to your computer and use it in GitHub Desktop.
Save toshinarin/443698dda38f5e57da0d4554348b8798 to your computer and use it in GitHub Desktop.
Bitbar plugin to show current power consumption with Nature Remo E
#!/bin/bash
# Preparation: Please install jq with homebrew
# API Reference: https://developer.nature.global/
# Get token from https://home.nature.global/
token="${NatureAPIToken}"
# Get id from `GET /1/appliances` API
# https://swagger.nature.global/
appliancesId="${NatureRemoEApplianceId}"
apiUrl="https://api.nature.global/1/appliances"
# The latter command is for fallback if proxy is used
res=`curl -s -H "Authorization: Bearer ${token}" ${apiUrl} || curl -s --proxy localhost:8888 -H "Authorization: Bearer ${token}" ${apiUrl}`
echo $res \
| /usr/local/bin/jq -r ".[] | select(.id == \"${appliancesId}\") | .smart_meter.echonetlite_properties[] | select(.name == \"measured_instantaneous\") | .val" \
| LC_ALL=en_US.UTF-8 awk '{printf("🔌%'"'"'d\n", $1)}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment