Question on scheduling an action

Disclaimer: I know about Schedy but have not looked into it yet.

Hear me out. The usecase is as follows:

I have a script outside HA that can read my analog water meter and send an mqtt msg to HA. Recently I added an mqtt client next to it so HA can trigger the capture as well.

At this moment I just use a cronjob to do a capture once every hour.

What I would like to have is doing a more dynamic capture. i.e. if there is a water increase, do another capture in 5 or 10 minutes. If there is no water increase, do the capture in 30 minutes. Still no water increase? Do 1 hour. Still nothing? Keep 1 hour intervals.

How would you be able to accomplish something like this in through Automations? I guess in AppDaemon this would be relatively easy.

I haven’t tried to do anything like this with any of my automations but I think you could if you added an input_number or input_select (I chose to use input_number in my example). You would also need to add a timer. With those things in place I think something like this should work:

- alias: Collect Water Usage
  id: 'collect_water_usage'
  trigger:
	  - platform: event
	    event_type: timer.finished
	    event_data:
	      entity_id: timer.collect_water_usage_interval
  action:
  	- service: {{ use this one to collect your water usage }}
	- service: input_number.set_value
    	data_template:
        	entity_id: input_number.collect_water_usage_interval
        	value: "
	        	{%- if senorValue <= currentWaterUsage -%}
					{%- if states.input_number.collect_water_usage_interval.state | int == 5 -%}
						30
					{%- endif -%}
					{%- if states.input_number.collect_water_usage_interval.state | int == 30 -%}
						60
					{%- endif -%}
				{% else -%}
					{%- if states.input_number.collect_water_usage_interval.state | int != 5 -%}
						5
					{%- endif -%}
				{% endif %}"
    - service: timer.start
        data_template:
        	entity_id: timer.collect_water_usage_interval
        	duration: "00:{{ states.input_number.collect_water_usage_interval.state | int }}:00"

@Skye just curious if this was helpful or solved your use case.

It’s still on my todo list :slight_smile:

1 Like