sensor data to shell script
Moderator: leecollings
-
- Posts: 15
- Joined: Monday 09 November 2015 6:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
sensor data to shell script
Hi
I wonder how i retreive a sensordata (ex temperature) to a shell script?
i want my pi to say the temperature in a scenario
Robert
I wonder how i retreive a sensordata (ex temperature) to a shell script?
i want my pi to say the temperature in a scenario
Robert
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: sensor data to shell script
Did you look at the json commands in the wiki?
Maybe this is a starting point. I use this script to let my iMac go to sleep depending on 3 switches in Domoticz:
The script grabs the sensors from roomplan 7 (so it only get the 3 switches instead of all used devices).
The litle jsonValue function decodes the json data and puts the status in variables.
Is one of the variables can't be set, the scripts exits.
If one of 3 statusses is 'On' a second script is called.
Maybe this is a starting point. I use this script to let my iMac go to sleep depending on 3 switches in Domoticz:
Code: Select all
#!/bin/bash
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://192.168.0.10:8084/json.htm?type=devices&used=true&plan=7"`
if [ -z "$DOMOTICZ" ]
then
exit 1
else
WEG=$(echo $DOMOTICZ | jsonValue Status 1)
SLAPEN=$(echo $DOMOTICZ | jsonValue Status 2)
IMACSLAPEN=$(echo $DOMOTICZ | jsonValue Status 3)
if [[ -z "$WEG" || -z "$SLAPEN" || -z "$IMACSLAPEN" ]] ;
then
exit 1
fi
if [ $WEG == "On" ] || [ $SLAPEN == "On" ] || [ $IMACSLAPEN == "On" ]; then
/Applications/MyApps/imacsleep.command
fi
fi
The litle jsonValue function decodes the json data and puts the status in variables.
Is one of the variables can't be set, the scripts exits.
If one of 3 statusses is 'On' a second script is called.
-
- Posts: 15
- Joined: Monday 09 November 2015 6:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: sensor data to shell script
i can call a webpage to get the data from a sensor, but i want to extract the Data value in a sh script
cant find it anywhere
cant find it anywhere
-
- Posts: 15
- Joined: Monday 09 November 2015 6:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: sensor data to shell script
can´t figure out how to mask out a ex temperature data from a shell script.
lika i said i can call a website with the temperatue status, adress etc
lika i said i can call a website with the temperatue status, adress etc
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: sensor data to shell script
Maybe you should post your code? And explain better what you want?
Do you want to grab a temperature from a website and push it to domoticz? Or do you want to rab a temperature from Domoticz and use it in a shell script?
Do you want to grab a temperature from a website and push it to domoticz? Or do you want to rab a temperature from Domoticz and use it in a shell script?
-
- Posts: 15
- Joined: Monday 09 November 2015 6:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: sensor data to shell script
yes, i have voicerss working .
and i want a shell script that says ex " Godmorning, the outside temperature is xx degress.
the temperature is taken from a sensor inside the domoticz
and i want a shell script that says ex " Godmorning, the outside temperature is xx degress.
the temperature is taken from a sensor inside the domoticz
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: sensor data to shell script
This should get you starting:
The variable $TEMP contains the temperature of thermometer with idx 278.
Value is for ex 20.40 so you should trim that a bit I guess.
Code: Select all
#!/bin/bash
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://192.168.0.10:8084/json.htm?type=devices&rid=278"`
if [ -z "$DOMOTICZ" ]
then
exit 1
else
TEMP=$(echo $DOMOTICZ | jsonValue Temp 1)
echo $TEMP
fi
Value is for ex 20.40 so you should trim that a bit I guess.
-
- Posts: 15
- Joined: Monday 09 November 2015 6:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: sensor data to shell script
THANKS ALOT!. worked fine
-
- Posts: 15
- Joined: Monday 09 November 2015 6:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: sensor data to shell script
noticed that i got temperature like 18,80 , how do i get it to 18.8?
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: sensor data to shell script
Do you get 18 comma 80 or 18 point 80?
Wouldn't it be better to just remove the decimal and just say the whole degrees?
Then you could use something like this:
Change TEMPCLEAN=${TEMP%.*} to TEMPCLEAN=${TEMP%,*} if comma is your decimal separator.
Wouldn't it be better to just remove the decimal and just say the whole degrees?
Then you could use something like this:
Code: Select all
#!/bin/bash
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://192.168.0.10:8084/json.htm?type=devices&rid=278"`
if [ -z "$DOMOTICZ" ]
then
exit 1
else
TEMP=$(echo $DOMOTICZ | jsonValue Temp 1)
TEMPCLEAN=${TEMP%.*}
echo $TEMP $TEMPCLEAN
fi
-
- Posts: 15
- Joined: Monday 09 November 2015 6:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: sensor data to shell script
that did it! THANKS!
Who is online
Users browsing this forum: No registered users and 1 guest