I’m not sure why this script (in script.yaml) doesn’t work. It is supposed to turn the air conditioner on or off, depending on the current state, but won’t turn it on or off (so neither the if or else part is working):
So, I’m assuming that my if command is broken, or I can’t include an if command in that location. However, I’m not getting any errors.
The sensor code is:
- platform: rest
name: AC Status
resource: http://192.168.1.192/SystemSettings
method: GET
verify_ssl: false
value_template: '{{ value_json.SysOn }}'
# Options - on, off
ac_mode_change:
alias: ac mode change
sequence:
- data_template:
data:
SystemON: >
{% if is_state('sensor.ac_status', 'off') %}
on
{% else %}
off
{% endif %}
url: http://192.168.1.192/SystemON
service: shell_command.ac_command
as @tom_l said, your data section needs to be a data_template, but don’t get that confused with the data section that you need to send to your command. Also, if this is expecting a JSON object, you need to use the 2nd example as the first example only returns a string representation of a JSON object where the second will be an actual json object.
Thanks for the feedback guys. I probably should have included my shell command for context:
ac_command: "curl --data '{{ data }}' {{ url }}"
It doesn’t need an actual json object, just the string. Neither of those suggestions are working out of the box, but it is after midnight, so I’ll look at them properly in the morning. I appreciate your help and I’ll let you know how I get on tomorrow having fixed the data_template issue, that was clearly a problem.
I don’t suppose there is a linux command to monitor what the curl/shell statement being produced is? It would be easier to debug if I could see the command? Or is there a log file that I can log it to somehow?
I solved it. Thanks for your help. it was the single quotes within the if statement, they needed removal, more like your second option (which I’ll revisit to see why I couldn’t get to work last night).