I didn’t get to it, yet. Pretty busy at work this week, hoping to get to it tomorrow!
-
Rule "if it starts to rain..."
-
Am I just to stupid or do I do smth wrong?
I set up my ShellSensor, filled in everything you said above and got in the command section
sudo echo /home/pi/pimatic-app/scripts/weather.sh
is this right?
Because otherwise I’ll get always an error…
my weather.sh looks like this:
#!/bin/bash # jsonval credit: https://gist.github.com/cjus/1047794 jsonval () { temp=`echo $haystack | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $needle` echo ${temp##*|} } dev_key='xxxxxxxxxxxxxx' city='Germering' state='OV' red=$(tput setaf 1) textreset=$(tput sgr0) haystack=$(curl -Ls -X GET http://api.wunderground.com/api/$dev_key/conditions/q/$state/$city.json) needle='weather' current_condition=$(jsonval $needle $haystack) echo -e $current_condition`
-
@quintz said in Rule "if it starts to rain...":
Am I just to stupid or do I do smth wrong?
I set up my ShellSensor, filled in everything you said above and got in the command section
sudo echo /home/pi/pimatic-app/scripts/weather.sh
is this right?
Because otherwise I’ll get always an error…
my weather.sh looks like this:
#!/bin/bash # jsonval credit: https://gist.github.com/cjus/1047794 jsonval () { temp=`echo $haystack | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $needle` echo ${temp##*|} } dev_key='xxxxxxxxxxxxxx' city='Germering' state='OV' red=$(tput setaf 1) textreset=$(tput sgr0) haystack=$(curl -Ls -X GET http://api.wunderground.com/api/$dev_key/conditions/q/$state/$city.json) needle='weather' current_condition=$(jsonval $needle $haystack) echo -e $current_condition`
The bash you pasted here there is a ’ after $current_condition so remove that.
Your command is
sudo echo /home/pi/pimatic-app/scripts/weather.sh
Im not quite sure why you use echo?
Try:
sudo /path/to/script/weather.sh
Dont forget to add a dev key to the script. You can get that from the weather underground api on their website.
-
The ` came from the forum command for code…
Tried the sudo path/to/script way but if I use that inside my shellSensor I allways get
[ShellSensor#wunderground-wetter] Error: Command failed: /bin/sh -c sudo /home/pi/pimatic-app/scripts/weather.sh sudo: unable to execute /home/pi/pimatic-app/scripts/weather.sh: No such file or directory
But the script is deffinetly there…
I X’ed the dev key out so normaly there is one in there
EDIT:
I decied to throw away the old weather.sh file and created a new one…
Don’t ask me WHY but now it works… -
@quintz said in Rule "if it starts to rain...":
The ` came from the forum command for code…
Tried the sudo path/to/script way but if I use that inside my shellSensor I allways get
[ShellSensor#wunderground-wetter] Error: Command failed: /bin/sh -c sudo /home/pi/pimatic-app/scripts/weather.sh sudo: unable to execute /home/pi/pimatic-app/scripts/weather.sh: No such file or directory
But the script is deffinetly there…
I X’ed the dev key out so normaly there is one in there
EDIT:
I decied to throw away the old weather.sh file and created a new one…
Don’t ask me WHY but now it works…Maybe you had a typo the first time
-
@quintz A couple of issues here:
As @Gleno0h pointed out the scipt contained in your last post contain a stray back-tick at the end. Remove it in case you have it on file. May be it just slipped in when you edited the postEDIT: you already commented on this one- You don’t need the sudo command here. The shell script has no requirements for that and pimatic runs as root anyway
- The shell script must be set to “executable” as @Gleno0h pointed out, i.e.
chmod +x /home/pi/pimatic-app/scripts/weather.sh
- The script uses the
tput
command which requires TERM to be set. Unfortunately, this is not the case when the shell command is executed from pimatic (in my setup, at least). If you get an error message like “No value for $TERM and no -T specified” you can work around the issue by adding the following to the script right after the first line:export TERM=xterm
- Now you’re set. The script works fine for me with the following device config:
{ "attributeName": "condition", "attributeType": "string", "command": "/home/pi/pimatic-app/scripts/weather.sh", "id": "shell-1", "name": "Weather", "class": "ShellSensor", "interval": 200000 }
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
OK, for me it finally works. I had to remove the
-e
afterecho
, otherwise in pimatic it would say “-e partly cloudy”. I also changed the script to use coordinates instead.# jsonval credit: https://gist.github.com/cjus/1047794 export TERM=xterm jsonval () { temp=`echo $haystack | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep$ echo ${temp##*|} } dev_key='xxxxxxxxxxxxxxxxxxx' coordinates='52.xxxxxx,13.xxxxxx' red=$(tput setaf 1) textreset=$(tput sgr0) haystack=$(curl -Ls -X GET http://api.wunderground.com/api/$dev_key/geolookup/conditions/q/$coordinates.json) needle='weather' current_condition=$(jsonval $needle $haystack) echo $current_condition
-
OK, now to the rules! Two questions:
- Should it really be like
WHEN condition of weatherbash is "Partly Cloudy" THEN turn lamp1 on
or shouldn’t it be something like
$weatherbash.condition gets updated and condition of weatherbash is "Partly Cloudy" THEN turn lamp1 on
to make sure the rule is fired whenever the status is updated? - Is there a way to setup a rule to check if a value has certain keywords like “rain” or “storm” in it instead of listing them all? Or should that be part of the script and if so, how would that work best?
(I’m not a developer, but I’m hacking my way through it…)
- Should it really be like
-
OK, now the rule is firing every 3 minutes - I was hoping “gets updated” means when the status changes to something other than before, not whenever the script is executed.
-
you could give it a try with
when $weatherbash.condition changes and ... then do something
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebookmake it so !
-
@GuybrushMR80 have you seen the conditions?
There is a large list with a lot of variation. To create a keyword converter in the bash should not be a problem but i think this script works best as is. Now you have the option to use rules for all the weather types.
As for your rules, indeed dont use if updated cause it fires everytime, because it updates.
You can create a filter for yourself in the bash to make Heavy Rain, Light Rain etc display rain.
EDIT: here is a example to filter and recreate output to what you want. I am nit going to add this to the script because i think this is user related. One want simple, one wants complicated
Replace
echo -e $current_condition
withif [[ $current_condition = *"Rain"* ]] ; then echo "Rain" fi
This will check for any string that contains the word “Rain” and convert it to Rain. Example, output Heavy Rain or Light Rain will become Rain. Thats what you want?
-
Awesome, that looks great - will test it over the weekend and report back!
EDIT:
I slightly changed it to make sure I can differentiate between “Rain” and everything else:
if [[ $current_condition = *"Rain"* ]] ; then echo "Rain" else echo $current_condition fi
Seems to work - let’s see how accurate that is. Maybe I need to add “Volcano Ash” or “Sandstorm” at some point but for now that should do the job. -
Ok now I have the rule in place since a few days and guess what: it didn’t rain! I’m not asking for it but I have to wait a few more days to see how accurate his works.
when $weatherbash.condition changes and condition of weatherbash is \"Rain\" then press dach_down and after 30 seconds press dach_stop and send pushbullet title:\"Dachluke geschlossen wegen Regen\"
-
@GuybrushMR80 said in Rule "if it starts to rain...":
Ok now I have the rule in place since a few days and guess what: it didn’t rain! I’m not asking for it but I have to wait a few more days to see how accurate his works.
when $weatherbash.condition changes and condition of weatherbash is \"Rain\" then press dach_down and after 30 seconds press dach_stop and send pushbullet title:\"Dachluke geschlossen wegen Regen\"
Rule looks ok.
Haha yeah testing is a pain, you can use use echo to send rain just for testing. If it works ill fine tune the script and make a tutorial when i am finished with our new house
-
I have a problem: The device I created is not updating the status anymore. When I execute the script in the command line, it returns “Scattered Clouds” while in pimatic it still shows “Clear”. I waited 10 minutes to allow it to refresh but it’s still “Clear”. Any idea what the reason might be?
My device:
{ "attributeName": "condition", "attributeType": "string", "command": "/home/pi/pimatic-app/scripts/weather.sh", "id": "weatherbash", "name": "weatherbash", "class": "ShellSensor", "interval": 180000 }
The logs don’t show any error… weird, isn’t it?
EDIT: When I click on the status “Clear” it in the webinterface it says
Condition: Clear @ 14:55:44
Now it’s 18:19 - so no update since 3.5 hours?
EDIT 2: Now I created a second device, using the same parameters - this is now returning an error message:
error [pimatic-shell-execute,ShellSensor]: Error getting attribute value weatherbash-2.condition: undefined 18:21:03 error [pimatic-shell-execute]: [ShellSensor#weatherbash-2] Error: Error getting attribute value for weatherbash 2: /home/pi/pimatic-app/scripts/weather.sh: 18: /home/pi/pimatic-app/scripts/weather.sh: [[: not found
-
@GuybrushMR80 what happens when you execute the script through ssh?
sudo /home/pi/pimatic-app/scripts/weather.sh
Post output
Also post your weather.sh since you made modifications.
Mine still works perfect and updates are good.
-
thanks for helping out!
This is the output:
/home/pi/pimatic-app/scripts/weather.sh: 18: /home/pi/pimatic-app/scripts/weather.sh: [[: not found Mostly Cloudy
And that’s the script:
# jsonval credit: https://gist.github.com/cjus/1047794 export TERM=xterm jsonval () { temp=`echo $haystack | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep$ echo ${temp##*|} } dev_key='xxxxxxxxxxxx' coordinates='xxxxxxxxxxx,xxxxxxxxxxx' red=$(tput setaf 1) textreset=$(tput sgr0) haystack=$(curl -Ls -X GET http://api.wunderground.com/api/$dev_key/geolookup/conditions/q/$coordinates.json) needle='weather' current_condition=$(jsonval $needle $haystack) if [[ $current_condition = *"Rain"* ]] ; then echo "Rain" else echo $current_condition fi
-
I think I got it, at least it doesn’t return an error anymore - I changed the if condition:
if [ $current_condition = *"Rain"* ] then echo "Rain" else echo $current_condition fi
-
@GuybrushMR80
Wrong. You are missing this line at the top:#!/bin/bash
Your error is that the shell doesnt know how to handle the code because it isnt defined!!