Shell command problems

I have configured this in my shell_command.yaml:

temp2log: sudo /bin/bash -c "echo '{{ states.sensor.temperature_158d0001b95f60.state }}' >> /home/homeassistant/.homeassistant/temp_balcone.log"

to run automatically every 3 hours in this way:

- alias: Log temp balcone
  trigger:
    platform: time
    hours: /3
    minutes: 00
    seconds: 00
  action:
    service: shell.temp2log

But if i run the template in ninjia editor i get the right temperature, while when running from automation in the temp_balcone.log i get:

{{ states.sensor.temperature_158d0001b95f60.state }}

Where am i wrong?

I suspect the shell command cannot take templates. But if you want to log states, you might check out the ideas in this thread

Thanks, i’ll take a look at it…