Turning a Telldus switch on/off based on the electricity price

Hi,
I am new to Home Assistant - I have it running on a Pi 4 and Home Assistant is connected to a Telldus Tellstick and hence several Telldus plugs; several Mill Smart plugs and a Shelley thermostat. My electricity supplier is Tibber. My ambition is to switch a Telldus switch connected to a heater “on”, when the electricity price is below a user defined threshold. I have read several Tibber automations in Home Assistant but haven’t managed to get them to work as I have hoped.
For my first attempt, I used an available template to alter the price_level from the 3-day to the 1-day calculation which worked but had the consequence of making my Tibber usage statistics invalid (well I think it was this).
For my second attempt, as variables have limited visibility, I then tried to make a binary sensor - based on the price threshold that could be used within the automation. I couldn’t get this to work as I don’t fully understand how to make variables (or attributes?) visible from the Helper-> Template in an automation.
So my third (and I hope final attempt), I have used some other examples to write the whole thing in just one automation. The automation is included below:

alias: Test price and switch lounge on
description: Test if price is < 0.9 * average
trigger:
  - platform: state
    entity_id:
      - sensor.electricity_price_home
    enabled: true
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              '{{ float(states('sensor.electricity_price_home')) <
              0.9 * float(state_attr('sensor.electricity_price_home',
              'avg_price')) }}'
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              device_id: 501831e1b42aafc3efebfa376b0c42ce
          - service: notify.notify
            data:
              message: >-
                "The electricity price is < average, now it is {{
                states('sensor.electricity_price_home') }} and
                average is {{
                state_attr('sensor.electricity_price_home',
                'avg_price') }}"
      - conditions:
          - condition: template
            value_template: >-
              '{{ float(states('sensor.electricity_price_home')) >
              0.9 * float(state_attr('sensor.electricity_price_home',
              'avg_price')) }}'
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              device_id: 501831e1b42aafc3efebfa376b0c42ce
          - service: notify.notify
            data:
              message: >-
                "The electricity price is > average, now it is {{
                states('sensor.electricity_price_home') }} and
                average is {{
                state_attr('sensor.electricity_price_home',
                'avg_price') }}"
mode: single

So the idea is to turn the switch on when the price is <= 0.9 of the average price. If the price is greater, it should turn off. This doesn’t work and I also don’t know where the messages should appear. Ideally I would like the messages to appear in the Logbook.

I have attached a graph showing the daily price. The red line is the average, the yellow line is 90% of it. So anything below this should turn the switch on. The other pngs show that Tibber price in the app agree with that in HomeAssistant and my graph for around noon.

I hope you have time to help me to get this working as I am sure it is something obvious that I have missed and don’t understand.

Thanks,
Mark.