Help with automation: trigger when temperature drops below

Can anyone spare the time to help me with another issue arising from trying to undertand my ASHP performance? I’m trying to work out how much energy is being used in heating the DHW so I can see what is being used for heating. I’ve added a Shelly EM to monitor the total energy going into the Ecodan ASHP and so far I’ve got these 2 automations:-
To start counting HW energy (my HW cycle starts at 15:00)

alias: Start HW cycle
description: ""
trigger:
  - platform: time
    at: "15:00:00"
condition: []
action:
  - service: input_number.set_value
    data:
      value: "{{states('sensor.shellyem_244cab419108_channel_1_energy') | float }}"
    target:
      entity_id: input_number.hw_energy_scatchpad
mode: single

This works fine (although it would be better not to reply on knowing at what time the cycle starts). Then the one that doesn’t work:-

alias: HW cycle end
description: Update HW energy estimate at and of hot water cycle
trigger:
  - platform: state
    entity_id:
      - sensor.hp_flowtemperature
    from: ">50"
    to: <50
condition: []
action:
  - service: input_number.set_value
    data:
      value: >-
        {{ states('input_number.hw_energy_est') | float +
        states('sensor.shellyem_244cab419108_channel_1_energy') | float -
        states('input_number.hw_energy_scatchpad') | float }}
    target:
      entity_id: input_number.hw_energy_est
mode: single

I thought a good trigger was when the flow temp from the ASHP dropped below the target tank temp of 50C. The visual editor added the inverted commas which I can’t edit out.
The automation doesn’t run & I’m not sure what to do next. Any thoughts? Any better approaches?

Use a Numeric State Trigger.

trigger:
  - platform: numeric_state
    entity_id:
      - sensor.hp_flowtemperature
    below: 50

It will trigger the moment when the sensor’s value crosses the threshold value. In other words, at the moment the sensor’s value decreases below 50. It won’t trigger again until the sensor’s value first increases above 50 and then decreases below 50.

Thanks, very elegant. Not sure how to test it until nest HW cycle though…
Would be very keen to hear anyone’s thoughts on how to identify when the hot water cycle starts, as I can’t identify any trigger from the Ecodan itself.

Unfortunately the automation did not trigger when the flow temperature dropped at the end of today’s hot water cycle. I can’t find any information logged to understand why.
Also, I set this up to accumulate the HW energy consumption, expecting to be able to use a sttistics card to see what I used in a prticular period. However the statistics card won’t accept an input_number.

Post the automation that failed to trigger.

If available, post a screenshot of the history graph for sensor.hp_flowtemperature.

Thanks for the question, as on pulling together the answer I spotted I had used the wrong flow temp! Lets see if the right one works tomorrow.

Can anyone help with this aspect please?