Automations Headache

Not entirely. If I run manually the pump does switch on, but when I switch the pump off and run the automation again, the pump switches on again. As I understand it, the template should prevent this from happening as it will only allow the automation to trigger once?

So there are times you are going to manually turn the pump off? How is that executed?

The condition is looking at the last time the automation was ran vs the last time the pump was turned off.

No the idea is to also turn the pump off with an automation, the pump should turn off when the PV Production is too low and the house starts pulling power from the grid or battery.

But this in its own creates an issue, PV Production may fluctuate during the day due to clouds, equipment coming online/offline etc. So the idea is, once the pump switches off, the “On” automation should switch i back on. This risk is due to the fluctuation that the pump will switch off, then on, then off, then on during the day which I want to avoid.

I’ll have to think about this, but I think moving the condition to the last time the pump ran vs the automation may be a better resolution.

What do you mean by moving the condition?

this

It controls the automation.

The entity_id may need to be the pump, not the automation. I still need to wrap my head around the situation. Really late for me

That actually makes more sense. I tested it with an entity that hasn’t ran today yet. Still the template returns a “False”. Shouldn’t it return “True” to trigger the automation and once the entity triggered once for the day only then the Template should return “False” to stop the automation triggering again?

Last trigged isn’t going to work with an entity.

{{ states.switch.your_pump.last_changed | default(today_at(), true) < today_at() }} may work.

BINGO!!! This seems to be working

I’m looking into today_at() vs now()

{{ states.switch.your_pump.last_changed | default(today_at()) < now() }}

Now might be working better, as it will always check against the current time. So if the entity changed before now it will return true?

Yes, that is what I was thinking. If it hasn’t run it’s not greater than now()

Edit…it will always be less than now. I need to edit the logic

I like the idea, I’m gonna try it.

I have a last hypothetical question. One of the conditions is that if the current forecasted/estimated power production is higher than the actual power production it should return true.

This is based of a single PV string facing North. I am thinking of adding a second PV string facing West in the future. This will entail 2 entities, a North and a West. How would I create a condition to add the estimated power productions of both these entities, ie.

IF “current_Power” < (Estimated Power_North + Estimated Power_West) then TRUE

If both are sensors you can create a group in Helpers.

Holy Crap! Thank you. You helped me immensely. I was always wondering what the helpers are for. Where / which channel can I watch on YouTube to teach me all of this? Including the template / Jinja2 languages?

I have never used video, learned/ learning everything from this forum.

Just keep asking questions!!

1 Like

I owe you a beer! Thank you! and to all that answered!!!

I still need to verify the time math so I’ll follow up tomorrow. Bed time for me!

No worries, thank you. Have a good night

Yes, you changed the example I provided and introduced an error. There’s no such thing as this.automation.pool_pump_new. It should be this.entity_id as shown in the example above. The entity_id in this.entity_id is a property of the this object (refer to the State Objects link below).


References

Available this data
State Objects


In addition, you cannot test a template that references the this object because it exists exclusively when the template is executed by (in this case) the automation after it’s triggered.

BTW, all the debugging steps you went through with LiQuid_cOOled weren’t needed and the end result is a condition with different logic than the original one.

That’s a subtle detail that wasn’t clear when you agreed to this statement:

There’s a subtle but important difference between restricting the automation (what I said and you agreed to) and restricting the pump to turn on once a day. The automation is unaware if you turn on the pump manually so it won’t count towards its ‘once a day’ restriction.

If you want the automation to confirm that the pump hasn’t been turned on then use the Template Condition suggested by LiQuid_cOOled. However, be advised that the value of last_changed is modified on startup. So if Home Assistant is restarted before the automation turns on the pump, the value of last_changed will be today’s date and time and the Template Condition will prevent the automation from turning on the pump. So that Template Condition introduces a potential failure scenario (i.e. automation won’t turn on the pump that day).

3 Likes