Start dishwasher with low prices

Hello together,

I tried to setup up starting the dishwasher with lowest prices with the help of this:

https://github.com/TheFes/cheapest-energy-hours/blob/f31184928d886264edd60315f9bc2c8536949431/documentation/6a-dishwasher_overnight.md

I changed the code a little bit to be able to play with some values.

- trigger: 
    - trigger: state
      entity_id: switch.siemens_geschirrspueler_powerstate
      from: "off" 
      to: "on"
      for: "00:00:10"
  sensor:
    - name: Starte Geschirrspueler
      unique_id: sensor.starte_geschirrspueler
      device_class: timestamp
      state: >
        {% set start = states('input_datetime.cheap_power_start') %}
        {% set end = states('input_datetime.cheap_power_end')   %}
        {% set sensor = 'sensor.epex_spot_data_net_price' %}          
        {% set hours = states('sensor.programmdauer_geschirrspueler') | float %}

        {% if states('input_boolean.cheap_power_tomorrow') == 'on' %}
          {% set tomorrow = true  %}
        {% else %}
          {% set tomorrow = false  %}
        {% endif %}
        
        {#{ tomorrow }#}
        {#{ start}#}
        {#{ end }#}
        {#{ hours }#}

        {% if hours >= 0 %}
          {% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
          {% set startingtime = cheapest_energy_hours(sensor='sensor.epex_spot_data_net_price', hours=hours, start=start, end=end, look_ahead=true, include_tomorrow=tomorrow) %}
          {{ as_timestamp(startingtime) | timestamp_custom('%H:%M', true) }}
        {% else %}
          False
        {% endif %}

        availability: >
        {{
          not is_state('sensor.siemens_geschirrspueler_operationstate','BSH.Common.EnumType.OperationState.Run')
        }}

“hours” come from here:

- trigger: 
    - trigger: state
      entity_id: switch.siemens_geschirrspueler_powerstate
      from: "off" 
      to: "on"
      for: "00:00:05"
  sensor:
    - name: "Programmdauer Geschirrspueler"
      unique_id: sensor.programmdauer_geschirrspueler
    
      state: >
        {% set date1 = as_timestamp(now()) %}
        {#{ date1 | timestamp_custom('%D-%H:%M', local=True) }#}

        {% set date2 = as_timestamp(states('sensor.siemens_geschirrspueler_remainingprogramtime')) %}
        {#{ date2 | timestamp_custom('%D-%H:%M', local=True) }#}

        {% set difference = date2 - date1 %}
        {% set hours = (difference / 3600) | float(0) | round(2) %}
        {{ hours }}

Then I made a test automation:

alias: Strompreis billig
description: ""
triggers:
  - trigger: time
    at: sensor.starte_geschirrspueler
conditions: []
actions:
  - action: notify.mobile_app_sm_g960f
    metadata: {}
    data:
      title: Strompreis TEST
      message: >-
        Starte Geschirrspüler mit Strompreis: {{
        states('sensor.starte_geschirrspueler') }}
  - device_id: 8e29dee0847528d111a543048a8af282
    domain: button
    entity_id: 3790da6843737a6b443d515632e46364
    type: press
    enabled: false
mode: single

Actually I disabled the start of the dishwasher for testing and decides to send a notification to my mobile.

Unfortunately this doesn’t work. I can run the automation manually then the notification reached my phone.

I can’t spot the mistake in my code. Dev-tools made correct output - but always string altough I convert output to timestamp.

Please help.

BR

Mine looks like this, maybe it can help

in template file

  - trigger:
      -  platform: time
         at:
           - '19:28'
           - '20:28'
           - '21:28'
    sensor:
      - unique_id: f8853830-bf81-46d4-85a9-379c25c3
        name: Vaskemaskine 2 Start Tid aften og nat
        device_class: timestamp
        state: >
          {%- set sensor = 'sensor.energi_data_service' -%}
          {% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
          {{ cheapest_energy_hours(sensor=sensor, hours=2, start='21:00', end='06:00', include_tomorrow=true) }}

in automation I use this as trigger to turn washing machine on

Hi,

thank you for your reply. As I can see its nearly the same code from the example.

Unfortunately it doesnt help.

Maybe anyone else has an idea whats wrong with my code?

Thank you in advance!