I’m trying to figure out a way to set up an automation to turn on / turn off a smart plug based on an entity that provide best energy prices (based on Hour and also price)… I’m open to best practices to configure this, but initially I was thinking to configure it based on Hour probably.
The entity I use is PVPC and the attributes I was aiming are “next_best_at” whih is a 24 Hour format, example: 19, 22, 23
So I think it would require a Float or some sort of date time conversion.
Someone have some example or idea to create this automation (specially the trigger) ? since it’s based on the value and the time
You don’t really need to know it… you can test the templates using the Template Editor tool. Just copy/paste each of the templates below in the tool. You may need to do one at a time, as the one that is wrong for your situation will likely just give an error message.
{{ now().hour in state_attr('sensor.pvpc', 'next_best_at') }}
{{ now().hour in state_attr('sensor.pvpc', 'next_best_at').rsplit(",") | map('int', 0) | list }}
Didn’t know this for testing. Just tested the following query
{{ now().hour in state_attr(‘sensor.pvpc’, ‘next_best_at’) }}
And the output is:
Result type: boolean
true
This template updates at the start of each minute.
This template listens for the following state changed events:
* **Entity**: sensor.pvpc
What I wonder is, Is this checking all the time once I start the Automation? Since when I start the Automation it stop, so not sure is if checking or not every hour
It checks the template at the start of each minute, but triggers require something to happen. The trigger will fire if the time change caused the template to render ‘true’ only when it was previously ‘false’. When you save or reload an automation and the template already equals ‘true’, the actions will not be executed.
If you need that functionality it can be added by including additional triggers and matching conditions.