Automation, script and command

Hello everyone,

I have a weather station with rain bucket heating I switch on and off with actual temperature as the trigger.
I have a website grandix.nl that shows all weather data and also if the heating is on or off.
For this I have an automation, a script and a executable bash script. It is all very basic but doesn’t work.
Is there someone who could give me some help please?

The bash script:

sudo /usr/bin/curl 'https://www.grandix.nl/dom-api/verwarming.php?sleutel=<my key>&status=aan'

The script:

'1576845635951':
  alias: grandix_verwarming_aan
  sequence:
  - below: '13'
    condition: numeric_state
    entity_id: sensor.temperatuur
  - device_id: 42d32952db44489d993c8a6d12008892
    domain: switch
    entity_id: switch.everspring_an157_plug_in_appliance_module_switch
    type: turn_on
  - service: shell_command.grandixverwarming_aan
    data:
      shell_command:
        grandixverwarming_aan: 'sudo ./grandixverwarming_aan.sh'

The automation:

- id: '201912201120'
  alias: bericht verwarming aan naar website grandix
  description: ''
  trigger:
    platform: state
    entity_id: switch.everspring_an157_plug_in_appliance_module_switch
    to: 'on'
  action:
    service: script.turn_on
    entity_id: script.grandix_verwarming_aan

In my logfile I see this:

[homeassistant.components.automation] Executing bericht verwarming aan naar website grandix#033[0m
[homeassistant.helpers.script] Script bericht verwarming aan naar website grandix: Running script#033[0m
[homeassistant.helpers.script] Script bericht verwarming aan naar website grandix: Executing step call service#033[0m

And then nothing happens anymore. My website is not changing.

Franklin

Is the account you run Home Assistant as able to run sudo without a password?

        grandixverwarming_aan: 'sudo ./grandixverwarming_aan.sh'

That runs grandixverwarming_aan.sh in the current folder. You’d be far better off specifying the full path.

Yes, the user can do that. I tried from the command line and it works. The problem is that Hass apperntly can’t fire the bash script.
After reading again and again my files I came to this:

automation:

- id: '201912201120'
  alias: bericht verwarming aan naar website grandix
  description: ''
  trigger:
    platform: state
    entity_id: switch.everspring_an157_plug_in_appliance_module_switch
    to: 'on'
  action:
    service: script.turn_on
    entity_id: script.grandix_verwarming_aan
- id: '201912201125'
  alias: bericht verwarming uit naar website grandix
  description: ''
  trigger:
    platform: state
    entity_id: switch.everspring_an157_plug_in_appliance_module_switch
    to: 'off'
  action:
    service: script.turn_on
    entity_id: script.grandix_verwarming_uit

script:

'1576845635951':
  alias: grandix_verwarming_aan
  sequence:
  - service: shell_command.grandixverwarming_aan
    data:
      shell_command:
        grandixverwarming_aan: '/home/homeassistant/.homeassistant/grandixverwarming_aan.sh'
'201912201350':
  alias: grandix_verwarming_uit
  sequence:
  - service: shell_command.grandixverwarming_uit
    data:
      shell_command:
        grandixverwarming_uit: '/home/homeassistant/.homeassistant/grandixverwarming_uit.sh'

For me it looks completly logical code, but for me this is new stuff so I am open to all suggestions.
BTW the full path didn’t solve it. Same errors remain.

It took me a few days, but at last I have it working.
My setup is now as follows:

configuration.yaml

shell_command: !include shellcommand.yaml

shellcommand.yaml

grandix_verwarming_aan: 'sudo /home/homeassistant/grandixverwarming_aan.sh'
grandix_verwarming_uit: 'sudo /home/homeassistant/grandixverwarming_uit.sh'

automation.yaml

- id: '201912201110'
  alias: verwarming_grandix_aan
  description: ''
  trigger:
  - below: '2'
    entity_id: sensor.temperatuur
    platform: numeric_state
  action:
  - device_id: 42d32952db44489d993c8a6d12008892
    domain: switch
    entity_id: switch.everspring_an157_plug_in_appliance_module_switch
    type: turn_on
  - data:
      entity_id: grandix_verwarming_aan
    service: script.turn_on
- id: '201912201115'
  alias: verwarming_grandix_uit
  description: ''
  trigger:
  - above: '3'
    entity_id: sensor.temperatuur
    platform: numeric_state
  action:
  - device_id: 42d32952db44489d993c8a6d12008892
    domain: switch
    entity_id: switch.everspring_an157_plug_in_appliance_module_switch
    type: turn_off
  - data:
      entity_id: grandix_verwarming_uit
    service: script.turn_on
- id: '201912201120'
  alias: bericht verwarming aan naar website grandix
  description: ''
  trigger:
    platform: state
    entity_id: switch.everspring_an157_plug_in_appliance_module_switch
    to: 'on'
  action:
    service: script.turn_on
    entity_id: script.grandix_verwarming_aan
- id: '201912201125'
  alias: bericht verwarming uit naar website grandix
  description: ''
  trigger:
    platform: state
    entity_id: switch.everspring_an157_plug_in_appliance_module_switch
    to: 'off'
  action:
    service: script.turn_on
    entity_id: script.grandix_verwarming_uit

scripts.yaml

'1576845635951':
  alias: grandix_verwarming_aan
  sequence:
  - service: shell_command.grandix_verwarming_aan
    data:
     shell_command:
       grandix_verwarming_aan: /home/homeassistant/grandixverwarming_aan.sh
'201912201350':
  alias: grandix_verwarming_uit
  sequence:
  - service: shell_command.grandix_verwarming_uit
    data:
      shell_command:
        grandix_verwarming_uit: /home/homeassistant/grandixverwarming_uit.sh

bash script grandixverwarming_aan.sh

/usr/bin/curl 'https://www.grandix.nl/dom-api/verwarming.php?sleutel=[mykey]&status=aan'

bash script grandixverwarming_uit.sh

/usr/bin/curl 'https://www.grandix.nl/dom-api/verwarming.php?sleutel=[mykey]&status=uit'

The part with the shellcommand.yaml was not easy to find so I hope other people can benefit offthis knowledge.
Thanks for all input.

Franklin