Am having a couple of issues getting HA to execute a cron job, and hoping a fresh set of eyes can point me in the direction as to why.
Firstly, whenever I reboot HA, the cron job gets removed from the crontab file. How do I stop this from happening ?
Secondly, I can’t actually get HA to run the cron job anyway.
In terms of setup, this is my HA install.
This is the code that I’ve added to the crontab file
*/15 * * * * run-parts /root/config/shell_scripts
This should run all/any shell scripts it finds in the shell_scripts folder every 15 minutes, although it doesn’t (it never runs at all). If I change it to the below (which should be another way of running the script), that also doesn’t work.
Instead of Cron jobs you could schedule it directly into HA using automation and shell commands. I have tons of these that I use for various purposes and doing it in HA has the added benefit of being able to set conditions on which scripts to execute and when. For example, here is what I use to truncate my log every hour:
I am new to HA, have a script that works if I run from a terminal window via ssh or the terminal added to HA. I have been able to find where to build the automation, but how do you get the shell_command linked to a service? All the searches talk about scripts, but not adding a service as a shell script.
I’m not sure exactly what you mean, if you created a shell command (and added to your yaml - default is /config/shell_commands.yaml) then the shell command is the service as you can see in the above example I posted.
Ok; Thank you. I was missing the part about adding that shell_commands.yaml to the configuration.yaml as an include. After I added the last line below the above example worked.
Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
Text to speech
tts:
platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml #New line to configuration.yaml to include linux shell scripts
shell_command: !include shell_commands.yaml
Hi p4mr, I have the same problem that my shell script in /etc/periodic/… does not execute. I have removed the .sh suffix, added #!/bin/sh to the start of the file, but I won’t execute. Any other good ideas??