Seneye Fish Tank Monitor Bash Script

All kinds of 'OS' scripts
ben53252642
Posts: 193
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version:
Contact:

Seneye Fish Tank Monitor Bash Script

Postby ben53252642 » Friday 12 May 2017 20:55

I wrote a Linux bash script for getting data from Seneye API and loading it into Domoticz,

Install requirements: apt-get install jq bc screen

Get your device ID number with this command:

Code: Select all

curl -s 'https://api.seneye.com/v1/devices?user=YOUREMAIL&pwd=YOURPASSWORD'


Enter your device ID, username and password, Domoticz IP and login details in the update.sh script.

Code: Select all

#!/bin/bash
while true; do

# Get the data
echo "Getting data from Seneye API..."
data=$(curl -s 'https://api.seneye.com/v1/devices/YOURDEVICEID?IncludeState=1&user=YOUREMAIL&pwd=YOURPASSWORD')

# Sort the data
temperature=$(echo "$data" | jq '.exps.temperature.curr' | sed -e s/[^0-9.]//g)
ph=$(echo "$data" | jq '.exps.ph.curr' | sed -e s/[^0-9.]//g)
nh3=$(echo "$data" | jq '.exps.nh3.curr' | sed -e s/[^0-9.]//g)
# Calculate slide expiry days
currentdate=$(date +%s)
unixexpiry=$(echo "$data" | jq '.status.slide_expires' | sed -e s/[^0-9.]//g)
math1=$(echo ""$unixexpiry"-"$currentdate"" | bc)
daysremaining=$(echo ""$math1" / 60 / 60 / 24" | bc)

# Display data in terminal
echo "temperature:" "$temperature"
echo "ph:" "$ph"
echo "nh3:" "$nh3"
echo "slide days remaining:" "$daysremaining"

# Load the data into Domoticz
echo "Sending data to Domoticz..."
curl -s "http://USERNAME:PASSWORD@192.168.0.5/json.htm?type=command&param=udevice&idx=619&svalue=${temperature}"
curl -s "http://USERNAME:PASSWORD@192.168.0.5/json.htm?type=command&param=udevice&idx=620&svalue=${ph}"
curl -s "http://USERNAME:PASSWORD@192.168.0.5/json.htm?type=command&param=udevice&idx=621&svalue=${nh3}"
curl -s "http://USERNAME:PASSWORD@192.168.0.5/json.htm?type=command&param=udevice&idx=622&svalue=${daysremaining}"

# Refresh data every 10 minutes
sleep 600
done



I use this startup.sh script to run it in the background using screen:

Code: Select all

# Start seneyemonitor
/usr/bin/screen -S seneyemonitor -d -m /root/seneye/update.sh


Screen Shot 2017-05-13 at 4.45.16 am.png
Screen Shot 2017-05-13 at 4.45.16 am.png (108.2 KiB) Viewed 235 times

Screen Shot 2017-05-13 at 4.45.52 am.png
Screen Shot 2017-05-13 at 4.45.52 am.png (132.61 KiB) Viewed 235 times

Screen Shot 2017-05-13 at 4.46.12 am.png
Screen Shot 2017-05-13 at 4.46.12 am.png (64.65 KiB) Viewed 235 times

Return to “bash / powershell / bat etc.”

Who is online

Users browsing this forum: No registered users and 1 guest