Create trigger for positive and negative electricity hours

Hi everyone,

I need some help creating a trigger for an automation that recognizes when my electricity tariff from my supplier changes from positive to negative and vice versa.

For the insiders: I live in Holland and use Zonneplan as my electricity supplier. In HA, I have a sensor that displays the current tariff. The tariff changes every hour. It is not necessary to trigger for every change within the spectrum (positive or negative). What I want is a trigger that detects when the current tariff goes negative and when it goes positive again.

I tried it with the code below, but that doesn’t work. Who can help me?

triggers:
  - trigger: state
    entity_id:
      - sensor.zonneplan_current_electricity_tariff
    to:
      - "-"
    id: Naar negatief
  - trigger: state
    entity_id:
      - sensor.zonneplan_current_electricity_tariff
    id: Naar positief
    from:
      - "-"
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Naar negatief
        sequence:
          - type: turn_off
            device_id: 6a913ee349c8cc266a0a0e9eff66d3b3
            entity_id: 55168ce46a49558f1fab98fdb78c6899
            domain: switch
          - action: notify.mobile_app_pixel_6
            metadata: {}
            data:
              message: Omvormer uitgezet vanwege negatieve prijzen!
      - conditions:
          - condition: trigger
            id:
              - Naar positief
        sequence:
          - type: turn_on
            device_id: 6a913ee349c8cc266a0a0e9eff66d3b3
            entity_id: 55168ce46a49558f1fab98fdb78c6899
            domain: switch
          - action: notify.mobile_app_pixel_6
            metadata: {}
            data:
              message: Omvormer aangezet vanwege positieve prijzen!
mode: single

State triggers are very literal. The trigger you have posted would only work if the value of sensor.zonneplan_current_electricity_tariff was exactly the string -

If the value of sensor.zonneplan_current_electricity_tariff is a number you would need to use either Numeric State triggers or Template triggers:

triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.zonneplan_current_electricity_tariff
    below: 0
    id: Naar negatief
  - trigger: numeric_state
    entity_id:
      - sensor.zonneplan_current_electricity_tariff
    id: Naar positief
    above: -0.00001
triggers:
  - trigger: template
    value_template: "{{ states('sensor.zonneplan_current_electricity_tariff')|float(0) < 0 }}"
    id: Naar negatief
  - trigger: template
    value_template: "{{ states('sensor.zonneplan_current_electricity_tariff')|float(0) >= 0 }}"
    id: Naar positief

I changed it to numerical and now it works. Thanks for the tip!