I need help to cut out a part of a string to know wich state a device has.
this is the echo from command line:
'POWER': 'On':
i will cut out the On
so that the switch shows the state of the device.
thanks
[Solved] cut out string from command line via shellSwitch
I need help to cut out a part of a string to know wich state a device has.
this is the echo from command line:
'POWER': 'On':
i will cut out the On
so that the switch shows the state of the device.
thanks
Do you have a logfile?
You can use this command to display On or Off or any other word after ‘POWER’:
cat /home/pi/power.log | awk {'print $2'} | sed "s/'//g"
Have created a logfile with your above echo and get this output
Now here’s the output if I change the logfile / your echo to ‘POWER’: ‘Off’
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebook
make it so !
I made a shellsensor device. Maybe you can work with this?
The Interval can be set to your needs.
{
"id": "powerontest",
"name": "Power Test Device",
"class": "ShellSensor",
"attributeName": "status",
"attributeType": "string",
"command": "cat /home/pi/power.log | awk {'print $2'} | sed \"s/'//g\"",
"interval": 10000
},
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebook
make it so !
Thanks, will test it tomorrow.
Ah OK - stupid me !!
Forgot a very important line of code at the device.
I updated the above device. Now you can use it within rules as follows :
IF $powerontest.status = "On" THEN do some stuff
Or vice versa
IF $powerontest.status = "Off" THEN do some stuff
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebook
make it so !
sry, the string i get is this one: {'MAIN:PWR': 'Standby'}
, when i execute this command in the command line:
sudo /root/programme/yamaha/yamaha.py PWR ? | awk {'print $2'} | sed "s/}//g" | sed "s/'//g"
i get this if the receiver is Off
Standby
and this when it is On
On
now i will use a shell switch like this one.
{
"id": "yamahapower",
"name": "Yamaha AVR",
"class": "ShellSwitch",
"onCommand": "sudo /root/programme/yamaha/yamaha.py PWR On",
"offCommand": "sudo /root/programme/yamaha/yamaha.py PWR Standby",
"getStateCommand": "sudo /root/programme/yamaha/yamaha.py PWR ? | awk {'print $2'} | sed "s/}//g" | sed "s/'//g"",
"interval": 10000
},
but when i try to start pimatic with that, i get the following error
17:01:04.922 [pimatic] error: Startup error: Error: Parse error on line 398:
17:01:04.922 [pimatic] error:>...{'print $2'} | sed ""s/"}
17:01:04.922 [pimatic] error:>-----------------------^
17:09:59.819 [pimatic] error:>Expecting 'EOF', '}', ':', ',', ']', got 'STRING'
17:09:59.819 [pimatic] error:> at Object.parseError (/root/pimatic-app/node_modules/pimatic/node_modules/cjson/node_modules/jsonlint/lib/jsonlint.js:55:11)
17:09:59.819 [pimatic] error:> at Object.parse (/root/pimatic-app/node_modules/pimatic/node_modules/cjson/node_modules/jsonlint/lib/jsonlint.js:132:22)
17:09:59.819 [pimatic] error:> at Object.exports.parse (/root/pimatic-app/node_modules/pimatic/node_modules/cjson/node_modules/jsonlint/lib/jsonlint.js:417:53)
17:09:59.819 [pimatic] error:> at Object.exports.parse (/root/pimatic-app/node_modules/pimatic/node_modules/cjson/index.js:88:28)
17:09:59.819 [pimatic] error:> at Framework._loadConfig (/root/pimatic-app/node_modules/pimatic/lib/framework.coffee:98:24)
17:09:59.819 [pimatic] error:> at new Framework (/root/pimatic-app/node_modules/pimatic/lib/framework.coffee:56:8)
17:09:59.819 [pimatic] error:> at /root/pimatic-app/node_modules/pimatic/startup.coffee:48:21
17:09:59.819 [pimatic] error:> at tryCatcher (/root/pimatic-app/node_modules/pimatic/node_modules/bluebird/js/main/util.js:24:31)
17:09:59.819 [pimatic] error:> at Function.Promise.attempt.Promise.try (/root/pimatic-app/node_modules/pimatic/node_modules/bluebird/js/main/method.js:31:24)
17:09:59.819 [pimatic] error:> at Object.module.exports.startup (/root/pimatic-app/node_modules/pimatic/startup.coffee:47:10)
17:09:59.819 [pimatic] error:> at run (/root/pimatic-app/node_modules/pimatic/pimatic.js:15:24)
17:09:59.819 [pimatic] error:> at /root/pimatic-app/node_modules/pimatic/lib/daemon.coffee:87:9
17:09:59.819 [pimatic] error:> at Object.oncomplete (fs.js:107:15)
17:09:59.824 [pimatic] info: exiting...
the on and off command are working, but i cant get the state
and i thing i have to convert the standby string to off so that the switch turn off when i turn the receiver off with my normal remote.
You need to escape the " characters as follows \"
You can replace standby with off if you use sed too. Will have a look at it.
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebook
make it so !
with this:
sudo /root/programme/yamaha/yamaha.py PWR ? | awk {'print $2'} | sed 's/}//g' | sed "s/'//g" | sed 's/Standby/off/' | sed 's/On/on/'
i got off
but when i remote the last doubble quotes with a single i dont get an output
and with this:
sed \"s/'//g\"
i get no output
and with this:
sudo /root/programme/yamaha/yamaha.py PWR ? | awk {'print $2'} | sed \"s/}//g\" | sed \"s/'//g\" | sed \"s/Standby/off/\" | sed \"s/On/on/\"
i got this in pimatic
17:50:06.849 [pimatic-shell-execute] error:
17:50:07.031 [pimatic] warn: Could not update variable yamahapower.state: ShellSwitch: unknown state=""!
Hm… There must be a way to get this working
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebook
make it so !
got it, with this command it works:
sudo /root/programme/yamaha/yamaha.py PWR ? | awk {'print $2'} | sed \"s/'//g\" | sed \"s/}//g\" | sed s/On/on/ | sed s/Standby/off/
Perfect! Regex, awk and sed are always tricky
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebook
make it so !