to build a generic shellswitch it will be nessesary to command like this…
curl http:///blabllaaa; if blubblub; then echo on; else echo of; fi
Pimatic-Shell-Switch General Problem
to build a generic shellswitch it will be nessesary to command like this…
curl http:///blabllaaa; if blubblub; then echo on; else echo of; fi
In my command with the if than else … the return is ever false.
but in the normal console the output works
could you pls. check your off command. either it’s a typo here or in your config ! there’s a 0 missing …
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebook
make it so !
I don’t know if bash scripts are supported as a command, as suggested create an getEnigmaPowerstate.sh with the contents of your device and execute this in the getState.
Such devices with simple web APIs are another use of this suggested plugin
https://forum.pimatic.org/topic/1696/regex-website-parser
Sadly I didn’t find the time to start any implementation and there are other plugins in the back of my head.
@bootinterupt For future postings please quote code and command sequences as described here: https://forum.pimatic.org/topic/1179/how-to-post-code-on-the-forum
Thanks!
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
in my actual pimatic i use multiple sh scripts to do that, and that works. But the way to make it use is to work with dummy shellswitches, many rules, log reader and logfiles with an tmpfs filesystem, to reduce the amount of writing do the sd-card.
That is not very smart.
it was much more smarter to do this directly in pimatic, because the state from every device atribute is directly useable in the pimatic variables.
ps: yes…copy and paste error…dm7020 instead of dm702…but this is not the problem…
can someone tell me, how it is possible to execute complex bash scripts directly in pimatic without external sh script files. Is there an especially syntax needed instead of normal working bash syntax.
To solve this problem is very usefull for anyone, this is not only for me helpfull. So please dear developer, can you solve this problem.
Ps: the pimatic developer team is making a great job …!!!
@bootinterupt Please provide log output, thanks
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
I think you have to escape the [[.
Try:
"getStateCommand": "if [[ $(curl -s http://dm7020/web/powerstate? |grep '<e2instandby>' | cut -f2 -d '>'| cut -f1 -d '<') = 'false' ]]; then echo on; else echo off; fi",
or better:
"getStateCommand": "curl -s http://dm7020/web/powerstate? |grep '<e2instandby>' | cut -f2 -d '>'| cut -f1 -d '<' && echo 'off'|| echo 'on'",
(I’m not sure whether the “;” is somehow falsly interpreted by pimatic.)
Hello dear community,
with the help of an workmate on my working place i have found the mistake.
This doesn´t work:
{
"id": "dream_7080",
"name": "DM7080",
"class": "ShellSwitch",
"onCommand": "curl --silent http://dm7080/web/powerstate=4",
"offCommand": "curl --silent http://dm7080/web/powerstate=5",
"getStateCommand": "if [[ $(curl -s http://dm7080/web/powerstate? |grep '<e2instandby>' | cut -f2 -d '>'| cut -f1 -d '<') = 'false' ]]; then echo on; else echo off; fi",
"interval": 1000
}
This works
{
"id": "dream_7080",
"name": "DM7080",
"class": "ShellSwitch",
"onCommand": "curl --silent http://dm7080/web/powerstate=4",
"offCommand": "curl --silent http://dm7080/web/powerstate=5",
"getStateCommand": "if [ $(curl -s http://dm7080/web/powerstate? |grep '<e2instandby>' | cut -f2 -d '>'| cut -f1 -d '<') = 'false' ]; then echo on; else echo off; fi",
"interval": 1000
}
The problem was the double [[ ]]…
But another mistake is printed at the pimatic website, manual for Shell-Switch-Device
{
"id": "light",
"name": "Lamp",
"class": "ShellSwitch",
"onCommand": "echo on > /home/pi/switchState",
"offCommand": "echo off > /home/pi/switchState",
"getStateCommand": "echo /home/pi/switchState",
"interval": 10000
}
The “getStateCommand” Example will not work…
If it is possible, please correct that.
@bootinterupt said in Pimatic-Shell-Switch General Problem:
The “getStateCommand” Example will not work…
What do you mean by it doesn’t work? Can you please provide more details, please.
EDIT: … and, please, quote code and command sequences in your posts as advised earlier. It is is important as the the forum software transforms some characters in normal texts such as quotes. Thanks!
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
a command like
“echo /home/pi/switchState”
as shown in the example will not work, because
the returncode in this case is the string
/home/pi/switchState
an not the content of switchState
But i have zhe next problem when i am creating the
shellswitch for a yamaha av receiver.
also this code in bash is working…
curl --silent -d “<YAMAHA_AV cmd=“GET”><Main_Zone><Power_Control><Power>GetParam</Power></Power_Control></Main_Zone></YAMAHA_AV>” http://192.168.1.13/YamahaRemoteControl/ctrl | grep On | cut -f5 -d ‘>’| cut -f1 -d ‘<’
the return code is “on” or “off”
In pimatic config.json this will not work because auf the " in the code
is there a various syntax possible to fix it.?
use the \ as an escape character
curl --silent -d \“<YAMAHA_AV cmd=\“GET\”><Main_Zone><Power_Control><Power>GetParam</Power></Power_Control></Main_Zone></YAMAHA_AV>\” http://192.168.1.13/YamahaRemoteControl/ctrl | grep On | cut -f5 -d ‘>’| cut -f1 -d ‘<’
thanks for your idea, i have tested this
put that won´t work
this command…curl --silent -d \“<YAMAHA_AV cmd=\“GET\”><Main_Zone><Power_Control><Power>GetParam</Power></Power_Control></Main_Zone></YAMAHA_AV>\” http://192.168.1.13/YamahaRemoteControl/ctrl | grep On | cut -f5 -d ‘>’| cut -f1 -d ‘<’
will result…
bash: Syntaxfehler beim unerwarteten Wort »<«
in bash console, and in config.json the state is always “null” because of syntax error
the general problem in the shellswitch getcommand or other executing
is, that pimatic try to interprete the code within the “…”
now i am searching for a way to send curl data as binary date,…may this could solve every problem…
my idea is to capture the binary code with wireshark and send it via “curl --data-binary”
@bootinterupt said in Pimatic-Shell-Switch General Problem:
thanks for your idea, i have tested this
put that won´t workthis command…curl --silent -d \“<YAMAHA_AV cmd=\“GET\”><Main_Zone><Power_Control><Power>GetParam</Power></Power_Control></Main_Zone></YAMAHA_AV>\” http://192.168.1.13/YamahaRemoteControl/ctrl | grep On | cut -f5 -d ‘>’| cut -f1 -d ‘<’
will result…
bash: Syntaxfehler beim unerwarteten Wort »<«
in bash console, and in config.json the state is always “null” because of syntax error
You also need to escape all (!) your < and > statements, also in bash itself. Normally these < and > are used for redirecting data/commands, etc.