Turn off device and flag a setting that it shouldn't run again for the day

Hello everyone,

Thanks for a great product, home assistant it great and although I am very new to it, I am having lots of fun with it.

I am intergating HS with my solar inverter and are then turning on geysers and pumps depending on available solar power, battery state of charge etc. One thing that I would like to do is to turn off the geyser when when it isn’t drawing any current (assuming that it has reached the desired temperature) and set a flag to not turn on the geyser again for the current day. The automation that starts the devices should then be able to check if this flag has been set and not turn on again for the current day.

I might be missing something but I suspect that ‘helpers’ might be helpfull to achieve this. I haven’t been able to ‘set’ an helper value from automation though.

Any thoughts or ideas will be appreciated.

If you want an automation to execute no more than once a day, you can add the following Template Condition:

condition:
  - "{{ state_attr(this.entity_id, 'last_triggered') < today_at() }}"

If the last time the automation triggered was prior to midnight, it will execute the automation’s action. If the automation already triggered today, its last_triggered will be greater than midnight and the condition will prevent execution of the action.

Note

Be advised that this template will fail if the automation is new and has never triggered before (because its last_triggered value will be none). There’s a way to avoid that (by employing the default filter) but I have chosen to exclude it to simplify the template.

1 Like

Thank you Taras, I will keep this in mind.

I have been able to set the input_number through an action which is exactly what I want becuase the device can be used more than once per day, and only set not to run again for the day under certain conditions. Now I just need to be able to add this check of the input_number to an automation condition to not trigger if this value is 1. I am not sure how to do this.

I think I came right nad will be able to do a full end to end test tomorrow morning.

I added the below as a condition and it seems to be working.

Which can also be achieved using the technique I mentioned by simply modifying the condition. After all, the technique you have chosen still requires a condition to test the input_number’s value.

Neat. I had no idea today_at() had a default value of midnight. Never even occurred to me to try it.

Credit goes to Petro who created the function, after musing about a need for it here (August 2021), and then posting an example that employed it without an argument here (October 2021). It wasn’t until December when I found a need for “today at midnight” and have been finding more applications for it ever since.

1 Like