jammin36
(Ben)
January 1, 2017, 4:25pm
1
Hi,
Im trying to show the temperature of my Pi3 cpu on the home screen of Home Assistant but keep receiving errors when using the following command script ? is there something wrong with the below ?
- platform: command_line
name: CPU Temperature
command: "cat /sys/class/thermal/thermal_zone0/temp"
unit_of_measurement: "°C"
value_template: '{{ value | multiply(0.001) }}'
silvrr
January 1, 2017, 6:43pm
2
What do you get when you run that command in terminal?
1 Like
What happens when you remove the quotes from this line?
command: "cat /sys/class/thermal/thermal_zone0/temp"
jammin36
(Ben)
January 1, 2017, 7:29pm
4
thanks, when running in terminal without the quotes it works fine, so the rest now put into home assistant should work ok now ?
jammin36
(Ben)
January 1, 2017, 7:31pm
5
ok scrap that, i receive these errors now
17-01-01 19:30:21 homeassistant.loader: Unable to find component command
17-01-01 19:30:21 homeassistant.loader: Unable to find component name
17-01-01 19:30:21 homeassistant.loader: Unable to find component platform
17-01-01 19:30:21 homeassistant.loader: Unable to find component value_template
17-01-01 19:30:21 homeassistant.loader: Unable to find component unit_of_measurement
silvrr
January 1, 2017, 7:45pm
6
Try single quotes. ‘Like this’
jammin36
(Ben)
January 1, 2017, 7:48pm
7
script in home assistant
platform: command_line
name: CPU Temperature
command: ‘cat /sys/class/thermal/thermal_zone0/temp’
unit_of_measurement: ‘°C’
value_template: ‘{{ value | multiply(0.001) }}’
errors
17-01-01 19:47:29 homeassistant.loader: Unable to find component platform
17-01-01 19:47:29 homeassistant.loader: Unable to find component value_template
17-01-01 19:47:29 homeassistant.loader: Unable to find component name
17-01-01 19:47:29 homeassistant.loader: Unable to find component unit_of_measurement
17-01-01 19:47:29 homeassistant.loader: Unable to find component command
Ok, that sounds like a formatting error in the config file:
A similar example looks like this:
- platform: command_line
name: Server Temp
command: /usr/bin/sensors | grep "Core 0" | cut -c16-19
unit_of_measurement: "°c"
I have that in a serperate ‘sensors.yaml’ file that is referred to the main ‘configuration.yaml’ file as:
sensor: !include sensors.yaml
And don’t forget the best way to show people your code in the comments is to highlight the section and use the “< / >” tool on it.
People will be able to help you faster that way
1 Like
silvrr
January 1, 2017, 7:56pm
9
Can you post with the same formatting as your config file?
Paste your text and then hit the < / > above your post.
Or post a screen shot if it’s easier.
Finally, is this all under ‘sensor’ as the component?
jammin36
(Ben)
January 1, 2017, 8:04pm
10
apologies, im still learning.
the below is literally all i have written so am i missing something ?
platform: command_line
name: CPU Temperature
command: 'cat /sys/class/thermal/thermal_zone0/temp'
unit_of_measurement: '°C'
value_template: '{{ value | multiply(0.001) }}'
jammin36
(Ben)
January 1, 2017, 8:07pm
11
sorry but this is a little confusing so am i right in thinking i need to create a new file saving it as sensors.yaml and then put sensor: !include sensors.yaml
in my configuration.yaml because when trying that i got many errors and home assistant would no longer start
Yes, you are correct. Put in you main configuration file the following line:
sensor: !include sensors.yaml
Then in sensors.yaml
write the following code:
# CPU temperature
- platform: command_line
name: CPU Temperature
command: "cat /sys/class/thermal/thermal_zone0/temp"
unit_of_measurement: "°C"
value_template: '{{ (value | multiply(0.001)) | round(1) }}'
It works for me. I added round(1)
at the end because I don’t need that many deciamal numbers, you can delete it if you want.
1 Like
jammin36
(Ben)
January 1, 2017, 8:12pm
13
ok but is there a specific area within my configuration.yaml that i should put that ?
No worries. Ok, we’ll ignore the separate file for now, so undo or comment-out those changes.
And we’ll get this right in you main ‘configuration.yaml’ file.
It should look like this I reckon:
sensor:
platform: command_line
name: CPU Temperature
command: 'cat /sys/class/thermal/thermal_zone0/temp'
unit_of_measurement: '°C'
value_template: '{{ value | multiply(0.001) }}'
I’d say you nearly have it. Try with & without those single quotes you have around the command.
The spaces in front of lines are specifically important and will always be multiples of two.
So in the above example there is no space before the word ‘sensor’, and then two spaces in front of all the lines below.
jammin36
(Ben)
January 1, 2017, 8:23pm
15
thanks, really appreciate the help but now i receive the error
17-01-01 20:21:41 homeassistant.loader: Unable to find component -sensor
home assistant will not work unless i put the - before sensor but then when it does run i get the above error ?
any ideas ?
Oops that one is on me!
try:
sensor:
- platform: command_line
name: CPU Temperature
command: 'cat /sys/class/thermal/thermal_zone0/temp'
unit_of_measurement: '°C'
value_template: '{{ value | multiply(0.001) }}'
See the example here: https://home-assistant.io/components/sensor.command_line/
Also, are you re-running Home Assistant each time you want to check?
If you are there’s a quicker way to check if the config files will work, just type in a terminal:
hass --script check_config
jammin36
(Ben)
January 1, 2017, 8:51pm
17
yes i’m restarting the service each time and now i still have an error
duplicate key: “sensor”
That error is not so bad, it’s telling you that you can only use the header ‘sensor’ once in your configuration.yaml file.
So have a look through and find the others lines you’ve used ‘sensor’ with, and then group them together under the one ‘sensor’ line.
All the lines after will follow the same indented style, so when you’ve them together it should look like this:
sensor:
- platform: command_line
name: CPU Temperature
command: 'cat /sys/class/thermal/thermal_zone0/temp'
unit_of_measurement: '°C'
value_template: '{{ value | multiply(0.001) }}'
- platform: command_line
name: Sensor Number 2
command: 'cat /sys/class/thermal/thermal_zone0/temp'
unit_of_measurement: '°C'
value_template: '{{ value | multiply(0.001) }}'
3 Likes
jammin36
(Ben)
January 1, 2017, 8:58pm
19
you my friend are a star !!
it was conflicting with another sensor for the sun which i have deleted because i don’t want or need it anyway.
is there anyway to complicate my temperature script to make it refresh every 5 minutes ? or does this automatically update on a set interval ?
thanks again
Glad to help, a very helpful soul here gave me pretty much the same assistance when I started with hass in Nov.
Now I’ve dashboards, and automations all over
The temp should update on its own every 2 minutes or so, iirc.
I really recommend breaking out your configuration.yaml file into smaller files.
It makes it easier to check for bugs, better readability, and you just experienced the ‘duplicate key error’ etc.
If you’re just starting, you’ll be amazed at the things you’ll have done very quickly - and that also means longer config files.
Lots of examples here that I used to get it done:
The formatting within the separate files is slightly different, so keep that in mind.
Enjoy, Hass is really an extraordinary thing!
I knew not a single bit of yaml or python 2 months ago. Now I can write APIs, didn’t think I had a bit of that in me!