Hi,
I want to have different scan_interval configuration from image_processing (for example, scan_interval: 1 for a minute when a motion sensor is activated), but I don’t get to do it, someone knows how to change scan_interval dynamically?
Thanks!
Hi,
I want to have different scan_interval configuration from image_processing (for example, scan_interval: 1 for a minute when a motion sensor is activated), but I don’t get to do it, someone knows how to change scan_interval dynamically?
Thanks!
Unfortunately I don’t think you can.
The way I do it is to set a very long scan interval in the sensor itself and then have two scripts.
The first works out the required delay (scan_interval
) based on whatever criteria you need and then passes that to a second script.
The second script has a delay
which is the length of time you want to wait between updates (which you passed to this script) before it calls the homeassistant.update_entity
service. Finally it starts script 1 again.
@klogg could you please post more information about your solution, I would like to implement it but don’t fully understand it, thanks
Something like this:
automation:
- alias: Sensor Update
trigger:
- platform: homeassistant
event: start
action:
#== stop the looping scripts
- service: script.turn_off
entity_id:
- script.set_sensor_update_interval
- script.loop_set_sensor_update_interval
- delay: "00:00:02"
#=== Start the loops
- service: script.set_sensor_update_interval
script:
#========================
#=== Set update interval sensor
#========================
set_sensor_update_interval:
sequence:
#== Stop the looping script
- service: script.turn_off
entity_id: script.loop_set_sensor_update_interval
- delay: "00:00:01"
#=== Call the looping script to set the sensor interval
- service: script.loop_set_sensor_update_interval
data_template:
interval: >
{% if [SOME_CONDITION] %}
12:00:00
{% elif [SOME_OTHER_CONDITION %}
1:00:00
{% else %}
00:00:30
{% endif %}
#====================================
#=== Looping script that sets the sensor interval
#====================================
loop_set_sensor_update_interval:
sequence:
#=== update the sensor
- service: homeassistant.update_entity
entity_id: sensor.SOME_SENSOR
- delay: "{{ interval }}"
- service: script.set_sensor_update_interval
thanks I will try to implement that solution