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:
- Go to Settings > Automations & scenes.
- Open an existing automation or script, or select Create.
- In Then do, select Add action.
- Search for and select Green Planet Energy: Get cheapest duration.
- Enter the Green Planet Energy price sensor in Entity ID.
- Set the duration in hours.
- Optional: Set Time range to limit the search window.
- Select Save.
Options in the UI
Duration, in hours, for which to find the cheapest time window. Allowed range is 0.5 to 24.
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:
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
Green Planet Energy sensor entity used to identify the integration instance.
Duration, in hours, for which to find the cheapest time window. Accepts values from 0.5 to 24.
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 usesfull_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.
AI assistants like ChatGPT or Claude can also explain actions or suggest the right one when you describe what you want in plain language.