Get cheapest duration

The Get cheapest duration action calculates the cheapest consecutive time window for a duration between 0.5 and 24 hours.

Using this action from the user interface

If you prefer building automations and scripts visually, Home Assistant walks you through this action step by step. You pick what to target, tweak a few options, and save. No YAML knowledge required.

To use this action in an automation or script:

  1. Go to Settings > Automations & scenes.
  2. Open an existing automation or script, or select Create.
  3. In Then do, select Add action.
  4. Search for and select Green Planet Energy: Get cheapest duration.
  5. Enter the Green Planet Energy price sensor in Entity ID.
  6. Set the duration in hours.
  7. Optional: Set Time range to limit the search window.
  8. Select Save.

Options in the UI

Entity ID

Green Planet Energy sensor entity used to identify the integration instance.

Duration

Duration, in hours, for which to find the cheapest time window. Allowed range is 0.5 to 24.

Time range

Optional time range to search within. Choose from full_day, day, or night.

Using this action in YAML

If you work directly in YAML, or you want to know exactly what Home Assistant does under the hood, this section has the technical reference. It lists the field names you use in YAML, their types, and which ones are required.

In YAML, refer to this action as green_planet_energy.get_cheapest_duration:

ActionActions are used in several places in Home Assistant. As part of a script or automation, actions define what is going to happen once a trigger is activated. In scripts, an action is called *sequence*. [Learn more]
action: green_planet_energy.get_cheapest_duration
data:
  entity_id: sensor.green_planet_energy_current_price
  duration: 3.5
  time_range: night

Options in YAML

entity_id string Required

Green Planet Energy sensor entity used to identify the integration instance.

duration float Required

Duration, in hours, for which to find the cheapest time window. Accepts values from 0.5 to 24.

time_range string

Optional time range to search within. Accepted values are full_day, day, or night. Default is full_day.

Response data

The action response includes:

  • duration: Requested duration in hours
  • average_price: Average electricity price in EUR/kWh for the selected window
  • start_time: Start timestamp of the cheapest window
  • end_time: End timestamp of the cheapest window
  • hours_until_start: Hours remaining until the selected start time
  • time_range: The applied time range

Example response:

{
  "duration": 6.25
  "average_price": 0.1985
  "start_time": "2026-06-20T11:00:00+02:00"
  "end_time": "2026-06-20T17:15:00+02:00"
  "hours_until_start": 13.3
  "time_range": "day"
}

Good to know

  • If you do not provide time_range, Home Assistant uses full_day.

Try it yourself

Ready to test this? Open Developer tools > Actions, search for this action, fill in the fields, and select Perform action. You see what happens on your actual entitiesAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more] without writing a line of YAML.

Still stuck?

The Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the action you’re calling and what you expected to happen, or share on our subreddit /r/homeassistant.

Tip

AI assistants like ChatGPT or Claude can also explain actions or suggest the right one when you describe what you want in plain language.