Esphome - code help

Hi,
I have two colour led connected to node mcu32 (red and green), in esphome it is defined as follows:

light:
  - platform: monochromatic
    output: led32
    id: red_led
    name: Red
    effects:
      - pulse:
          name: "Slow Pulse"
          transition_length: 1s
          update_interval: 2s
          min_brightness: 0%
          max_brightness: 35%
      - pulse:
          name: "Medium Pulse"
          transition_length: 1s
          update_interval: 1s
          min_brightness: 0%
          max_brightness: 65%
      - pulse:
          name: "Fast Pulse"
          transition_length: 250ms
          update_interval: 400ms
          min_brightness: 0%
          max_brightness: 100%
      - strobe:
          name: "Strobe Red"
          colors:
            - state: false
              duration: 1s
            - state: true
              brightness: 75%
              duration: 1s                                      
  - platform: monochromatic
    output: led33
    id: green_led
    name: Green  
    effects:
      - pulse:
          name: "Slow Pulse"
          transition_length: 1s
          update_interval: 2s
          min_brightness: 0%
          max_brightness: 35%
      - pulse:
          name: "Medium Pulse"
          transition_length: 1s
          update_interval: 1s
          min_brightness: 0%
          max_brightness: 65%
      - pulse:
          name: "Fast Pulse"
          transition_length: 250ms
          update_interval: 400ms
          min_brightness: 0%
          max_brightness: 100%
      - strobe:
          name: "Strobe Green"
          colors:
            - state: true
              brightness: 75%
              duration: 1s
            - state: false
              duration: 1s    

I also have a text sensor defined as follows:

text_sensor:
  - platform: homeassistant
    id: battery_power
    entity_id: sensor.battery_power

this returns value of my home battery. When the values are negative i.e. -200 the battery is charging, when 200 the battery is charging
What I now want is to use that two colour led to indicate what is happening with the battery:

  • battery discharging > 1700
    green led off,
    red led flashing (effect Fast Pulse)
  • battery discharging rate from 1000 to 1700
    red led flashing (effect Medium Pulse), green off
  • battery discharging rate from 1 to 1000
    red led flashing (effect Slow Pulse), green off
  • battery @ 0 (sitting idle) - red and green are flashing (effects strobe red and strobe green)
  • battery charging (basically reverse of discharging but the green is doing all the flashing and red is off)

Sounds simple on the paper but I’m not sure how to code it in esphome - I suspect dreadful lambdas will have to be used?
Can any point me in the right direction?
Thanks

First question: Can you not import that HA sensor as a number, rather than text? Will make things much easier:

sensor:
  - platform: homeassistant
    id: battery_power
    entity_id: sensor.battery_power
    on_value_range:
      - below: 0
        then:
          - switch.turn_on: relay_1 # Your flashy light stuff here
      - above: 0
        below: 1
        then:
          - switch.turn_on: relay_1 # Your flashy light stuff here      - above: 1
      - above: 1
        below: 1000
        then:
          # More flashy stuff
      - above: 1000
        below: 1700
        then:
          - # More flashy stuff     
      - above: 1700
        then:
          - # etc...

I think above means “equal to or greater than”. And below means “less than” - but I haven’t had time to fiddle lately and it’s a while since I used this. Have a fiddle with the values and you will sort it out