Advice on automating dishwasher start time based on dynamic energy prices

I realize this may be a common task that many have already implemented in various ways but with the huge numbers of scripts and integrations available, I have a hard time getting started.

My situation is as follows:
I have a Bosch dishwasher connected with HASS via the home connect integration. This allows me to remotely start the programme.
I also fetch 15min dynamic energy pricing data using the Nordpool intergration and a custom template script based on this community post.

What I want, is an automation that starts the dishwasher programme at the right time to ensure the lowest price. However, it needs to be done either before 7am or 5pm. Ideally, this would take into account the actual energy consumption profile of the programme.

If anyone here can advise me on the best way to achieve this (with custom templates and automations or with an integration (either core or HACS), I would be very much obliged.

Thanks!

I think you want this macro, which was written by @TheFes and is well documented. There are examples in the documentation as well.

Many thanks for the recommendation! That macro seems to do exactly what want.

I now do have a follow-up question I hope you can also help me with. Based on the macro documentation, I have now setup sensor.dishwasher_evening_start_time which records the optimal start time in the evening when the dishwashers remote start is on and its door is closed.

However, my dishwasher needs a start command with a delay-time in seconds. Therefore, I have setup the draft automation below, which I now want to change such that it 1. calculates the delay time between now() and sensor.dishwasher_evening_start_time in seconds and 2. inputs that number at value:. But I am not sure how to do it.

- id: '1760042403818'
  alias: Start Dishwasher During Evening
  description: ''
  triggers:
  - trigger: state
    entity_id:
    - sensor.dishwasher_evening_start_time
  conditions: []
  actions:
  - device_id: 6054700123147695f575d1f14fdcf90b
    domain: number
    entity_id: 49bf7a3b88921572e0c9c0efd64dc7cf
    type: set_value
    value: 10 # input delay in seconds here
  mode: single

I hope you can give me some directions

PS I realise that I can more easily trigger the start at the start-time - but I prefer to see the delay time in the dishwasher display as soon as the start-time is set.

You’ll need to use templates, which also means you can’t use a device action. Which is fine, those should be avoided at all costs anyways. If you’re selecting actions from the dropdown, go past “devices” and pick the action specific for the entity type you want to affect. In this case, “number”.

actions:
  - action: number.set_value
    metadata: {}
    data:
      value: "{{ (states('sensor.dishwasher_evening_start_time') | as_datetime - now()).total_seconds() }}"
    target:
      entity_id: number.dishwasher_delay
1 Like

Just to update for anyone who is interested in doing the same, my question was incorrect because number.set.value does not work with number.dishwasher_delay bosch home connect integration. My current working code using the cheapest_energy_hours macro is below:

action: home_connect.set_program_and_options
data:
  device_id: <device id>
  affects_to: active_program
  b_s_h_common_option_start_in_relative: >-
    {% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %} {{
    (cheapest_energy_hours(sensor='sensor.nordpool_electricity_prices',
    hours=5, start='20:00', end='07:00', look_ahead=true,
    include_tomorrow=true) | as_datetime - now()).total_seconds() | int }}
  program: dishcare_dishwasher_program_eco_50

with inspiration from Home connect - Bosch dishwasher delayed start - #6 by tboss