Hi Community,
I have scripted some command_line sensors that require parameters to be set before execution. For checking the parameters I have set up the availability tag. Sadly it seems like to be executed before checking the availability. From documentation I would expect the following behavior:
- Startup HomeAssist Server
- Try execute Command_line sensor (Check availability)
A) True: Command_line gets executed and will be executed again when sensor_interval is reached.
B) False: Command_line gets checked again periodically if availability template signals „available“
Instead the following seems to be the case:
- Startup HomeAssist Server
- Command_line sensor is executed besides of unavailability. State is set to unavailable.
- Command_line gets executed again after sensor_interval is reached.
- sensor:
unique_id: waste_commandline_city
name: waste_commandline_city
scan_interval: 3600
availability: >-
{% if
is_state('sensor.home_rest_address', 'OK') and
state_attr('sensor.home_rest_address', 'city') != none and
state_attr('sensor.home_rest_address', 'district') != none
%}
{{
(state_attr('sensor.home_rest_address', 'city') | length) > 2 or
(state_attr('sensor.home_rest_address', 'district') | length) > 2
}}
{% else %}
{{ false }}
{% endif %}
command: 'curl ''https://zac.jumomind.com/mmapp/api.php?r=cities_web''
| jq ''.[]
| .name |= ascii_downcase
| select(
(.name == "{{ state_attr(''sensor.home_rest_address'', ''district'') | lower }}")
or (.name == "{{ state_attr(''sensor.home_rest_address'', ''city'') | lower }}")
)'''
json_attributes:
- name
- _name
- id
- area_id
value_template: >
{% if value_json is defined %}
{{ "OK" }}
{% else %}
{{ "Error" }}
{% endif %}
Problem is that the rest command is executed without the nessesary paramters and therefore throws the following error in the event log:
JSON result was not a dictionary
Logger: homeassistant.components.command_line
Source: components/command_line/sensor.py:169
Integration: Command Line (documentation, issues)
and
Empty reply found when expecting JSON data
Logger: homeassistant.components.command_line
Source: components/command_line/sensor.py:173
Integration: Command Line (documentation, issues)
Workaround:
Create and Automation that triggers homeassistant.update_entity on the sensor.
Question:
Is there any other way to reach the goal of not sending useless requests to the rest endpoint? Am I doing something wrong? Why is the command_line executed anyway?