Trigger an Action on Specific Date & Time

Sounds like you need a tab open to your HA in your web browser :wink: I have a pinned tab in my “main” browser so it’s easier to do stuff in my HA.

And when you’re up for it, you can even automate this (probably), but first steps first.

OK I bowed to the pressure and created 3 new input number helpers to hold the date and the 2 new values. Then added an Entities card to my Dashboard


followed by an update to the Automation.

alias: Electricity Rate Change
description: ""
trigger:
  - platform: time
    at: "00:01:00"
condition:
  - condition: template
    value_template: >-
      {{ states('input_datetime.electricity_rate_change_date') ==
      now().strftime('%Y-%m-%d') }}
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.electricity_day_rate
    data:
      value: "{{ states('input_number.electricity_upcoming_day_rate') }}"
  - service: input_number.set_value
    target:
      entity_id: input_number.electricity_kwh_rate
    data:
      value: "{{ states('input_number.electricity_upcoming_kwh_rate') }}"
mode: single

In light of what you posted in another topic (ability to programmatically disable a trigger), if you want it to trigger at a specific time on a specific date then I suggest you simply use Local Calendar, to store the date and time, and a Calendar Trigger to trigger the automation.

Yes you’re right, that would overcome my minor worry. I don’t think I’ve got that integration. Before I go down that route would I still be able use the Entities GUI Card to enter the date?

Edit:
I had a look and installed Local Calendar, but found I had to create an ‘update’ event to trigger the automation in the Calendar panel, then enter the new rates separately on my GUI card. I’d prefer to keep everything in one place ie the GUI card I showed above.

If, for testing purposes, you scheduled an Calendar event occuring within 15 minutes, you would need to force a refresh otherwise it shouldn’t be necessary.

A Calendar event’s description field can be used to store related data (such as the new rates). No separate helpers are needed.

Anyway, you now have at least two different ways to achieve your goal and can choose whichever one suits you best.

I’ve no idea how i would extract the new rates from the description field of the event. I tried googling it but no success.

Easiest is to simply use a space to separate the two values.

0.62726 0.23838

The Calendar Trigger will generate a trigger variable and the data you put in the event’s description field will be in trigger.calendar_event.summary. (No idea why it’s called summary instead of description but there it is).

You can extract the two values like this:

{% set day_rate, kwh_rate = trigger.calendar_event.summary.split() | map('float', 0) %}

OK. I’ve probably gone overboard but it’s been a learning experience. I’ll post here in case it helps others.

I wanted to create something that would update my Electricity Day and kWh rates on a particular date as soon I get notification of a change from my supplier; then I can forget about it! A Calendar entry seemed to work and I started out with an automation that run every day checking if the event had been reached. I didn’t like that as I wanted to trigger the automation just the once. 123 Taras suggested a Calendar entry with the data in it and a Calendar trigger for the Automation. I wanted a nice Front-End for entering the data via a dashboard.
This is what I’ve now got (it may still not be perfect).
Three Helpers -

input_datetime:electricity_rate_change_date
input_number.electricity_upcoming_day_rate
input_number.electricity_upcoming_kwh_rate

A Script that reads these 3 helper and creates a calendar event, writing the new rates into the description field in the format 0.12345 0.98765.

alias: Commit Electricity Tariff Change
sequence:
  - service: calendar.create_event
    data:
      summary: Electricity Rate Change
      description: >-
        {{states('input_number.electricity_upcoming_day_rate')}}
        {{states('input_number.electricity_upcoming_kwh_rate')}}
      start_date_time: "{{states('input_datetime.electricity_rate_change_date')}} 00:01:00"
      end_date_time: "{{states('input_datetime.electricity_rate_change_date')}} 00:02:00"
    target:
      entity_id: calendar.calendar_triggers
mode: single

A GUI Dashboard Card where I can enter the details and commit the Event.

And an Automation that gets triggered by the event. It reads the new rates from the description field (ie not the helpers).

alias: Calendar Trigger
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.calendar_triggers
condition:
  - condition: template
    value_template: "{{ trigger.calendar_event.summary == 'Electricity Rate Change' }}"
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.electricity_day_rate
    data:
      value: "{{ trigger.calendar_event.description.split()[0] | float }}"
  - service: input_number.set_value
    target:
      entity_id: input_number.electricity_kwh_rate
    data:
      value: "{{ trigger.calendar_event.description.split()[1] | float }}"
mode: single

It’s not perfect; you can create multiple events if you press the RUN button over and over. I might update the script to clear the form (the helper entities) and I would have like to have the form in a pop-up dialogue box, but that’s another rabbit hole.
Hope that’s some help.