Time of sensor as a trigger

Hello,

I want to use the sensor sensor.power_highest_peak_time_today (from the Forecast Solar integration).
The sensor has a time when the highest peak of energy production is expected.

So I want to fire an automation when the time of the sensor is now or was earlier this day. This last one is just a safety. Like let’s say first the sensor had time 13h but at 12h45 the sensor time was changed to 12h30 for example.

Anyone that can guide me how to set this as a trigger?

Post an example of the sensor’s value. Does it literally have this format: 12h30

In addition, go to Developer Tools > States and check if the sensor’s attributes contains device_class: timestamp

here you go :wink:

sensor

sensor2

alias: example
trigger:
  - platform: time
    at: sensor.power_highest_peak_time_today
condition: []
action:
  ... etc ...

A Time Trigger can use a sensor to provide the time when it should trigger provided that the sensor’s device_class is timestamp and the sensor’s value is presented as datetime in ISO format. It looks like your sensor meets all of the requirements.

Reference: Time Trigger

Be advised that it will only trigger on the time and date specified by the sensor’s value.

Ok that was pretty simple :grinning: :grinning: :grinning:

Thought it was not possible because in the visual editor the sensor did not show up as selectable.

But thanks mate!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

This automation is working expect when the following happens:

For example today. Time of the entity was 14h00.
At 13h13 the time of the entity changed from 14h to 13h. But ofcourse the automation did not trigger.

How can I trigger the automation when the time of the entity = ‘now’ or before ‘now’

platform: time
at: sensor.power_highest_peak_time_today
id: Hoogste piek enery verwacht komende uur
trigger:
  - platform: state
    entity_id: sensor.power_highest_peak_time_today
  - platform: time
    at: sensor.power_highest_peak_time_today
condition:
  - condition: template
    value_template: "{{ states('sensor.power_highest_peak_time_today')|as_timestamp <= now()|as_timestamp }}"
action:
   ...

That will trigger every time the sensor changes and its new state is now or earlier; or when the time on the sensor is reached.

great thanks!

For future reference, the original question was answered and you had marked it as the Solution.

Ten days later, you asked a different question in the same topic and marked its reply as the Solution (thereby removing the Solution tag from the answer to the original question).

Only one post in the entire topic can be the Solution to the original question. Now users looking for an answer to the original question are led to a reply for a different question.

In the future, feel free to ask follow-up questions in a separate topic (and optionally include a link to other topics). It helps to make the organization of questions/answers/solutions more straightforward for other users.

I usually agree with you on this, but I think the OP was right this time. The original question was:

Your solution appeared to work and got the Solution given, but then the OP realised it only fired at the time of the sensor but didn’t do the second part so asked again — and I filled in the second part (I hope correctly).

Genuinely not trying to steal Solutions here :smiley:

No worries; no accusations of ‘stealing’.

OP chose a Solution post 10 days ago so the assumption is that the suggestion was tested and solved the problem. However, apparently not (because ten days later they rephrased the question).

Let’s not overlook the fact that often users post questions that don’t accurately reflect what they actually wish to achieve (sometimes it’s even the wrong question for what they actually want).


Question for you: Is the Time Trigger still needed now that the automation’s State Trigger is triggered every time the sensor changes state?

The only reason I can think of for retaining the Time Trigger is if the sensor never changes state all day but that seems somewhat unlikely (unless it can predict the time of maximum energy production a full day in advance).

Yes, I think so. At some point at least once a day, the sensor will change to a new time.

If that time is in the future, the state trigger will fire but the condition will not be met and will stop anything happening. Once the actual time reaches the sensor time, the time trigger will fire and the condition will not stop it. I think this is still necessary.

If (as per OP example) the sensor jumps from a future to a past time , the state trigger will fire and the condition will be met allowing the action to run.

Yes bot triggers are still neccessary.

First for when time of sensor is ‘now’. and second if sensor changed to a time in the past.

Some time ago, but thanks, that solved this for me too after quite some strugling!