Building effects in esphome

I’m trying to add conditions to my yaml so I can control the last light either cwww or rgb that was turned on: -
6 buttons need the conditional depending on the last light turned on: -
On,
Off,
Dim-
Bright+
Warm (Colour-)
Cool (Colour+)

See code below: -

substitutions:
  device_ssid: "Dining Room Light"
  device_name: diningroomlight
  device_main_description: "RGBWW Ceiling LED light with RF remote located in Dining Room with discreet Tunable White & RGB Rear Light (shows up as separate lights)."
  device_description: Dining Room Light - Main Light
  friendly_name: "Dining Room Light - Tunable White"    # Put the name that you want to see in Home Assistant.
  device_name_rgb: diningroomlightrgb
  device_description_rgb: "Dining Room Light - RGB Rear."    # Put the name that you want to see in Home Assistant.
  friendly_name_rgb: "Dining Room Light RGB"
  frequency_rgb: 100 Hz
  frequency_cw: 250 Hz
  frequency_ww: 250 Hz

esphome:
  name: ${device_name}
  platform: ESP8266
  board: esp01_1m

wifi:
    ssid: !secret wifi_1st_ssid
    password: !secret wifi_1st_password

    # Enable fallback hotspot (captive portal) in case wifi connection fails
    ap:
      ssid: ${device_ssid}
      password: !secret ap_password

captive_portal:

# Enable logging
# Example configuration entry
debug:

# Logger must be at least debug (default)
logger:
  level: debug

# Enable Home Assistant API
api:
  password: !secret api_password

ota:
  password: !secret ota_password

web_server:
  port: 80


output:
  - platform: esp8266_pwm
    id: output_red
    pin: GPIO5
    max_power: 100%
    frequency: ${frequency_rgb}
  - platform: esp8266_pwm
    id: output_green
    pin: GPIO4
    max_power: 100%
    frequency: ${frequency_rgb}
  - platform: esp8266_pwm
    id: output_blue
    pin: GPIO14
    max_power: 100%
    frequency: ${frequency_rgb}
  - platform: esp8266_pwm
    id: output_cold_white
    max_power: 100%
    frequency: ${frequency_cw}
    pin: GPIO12
  - platform: esp8266_pwm
    id: output_warm_white
    pin: GPIO13
    max_power: 100%
    frequency: ${frequency_ww}
    
remote_receiver:
  pin:
    number: GPIO2
    inverted: True
  dump: 
  - nec
#  tolerance: 20%
#  buffer_size: 1kB
#  filter: 2us
#  idle: 4ms

binary_sensor:
  - platform: remote_receiver
    name: "On Button"
    nec:
      address: 0xFF00
      command: 0xC03F
    on_press:
      then:
        - light.turn_on: "${device_name}"
       
  - platform: remote_receiver
    name: Off Button"
    nec:
      address: 0xFF00
      command: 0x20DF
    on_press:
      then:
        - light.turn_off: "${device_name}"

  - platform: remote_receiver
    name: "Night Mode Button"
    nec:
      address: 0xFF00
      command: 0x906F
    on_press:
      then:
        - lambda: |-
            auto call = id(${device_name_rgb}).turn_off();
            call.perform();
            call = id(${device_name}).turn_on();
            call.set_color_temperature(500); // in mireds
            call.set_brightness(0.08);
            call.set_transition_length(1000); // in ms
            call.perform();
        - delay: 0.1s

  - platform: remote_receiver
    name: "Main Light Button"
    nec:
      address: 0xFF00
      command: 0x50AF
    on_press:
        then:
        - lambda: |-
            auto call = id(${device_name_rgb}).turn_off();
            call.perform();
            #define cwwwmode1 100mireds //Cool White
            #define cwwwmode2 300mireds //Natural White
            #define cwwwmode3 500mireds //Warm WHite
            static int cwwwmode = 1;
            call = id(${device_name}).turn_on();
            call.set_transition_length(1000);
            switch(cwwwmode)
            {
            case 1: call.set_color_temperature(100);
                    break;
            case 2: call.set_color_temperature(300);
                    break;
            case 3: call.set_color_temperature(500);
                    break;
            }
            cwwwmode++;
            if(cwwwmode == 4)
            {
              cwwwmode = 1;
            }
            call.perform();
            
  - platform: remote_receiver
    name: "Mood Light Button"
    nec:
      address: 0xFF00
      command: 0xD02F
    on_press:
      then:
        - lambda: |-
            auto call = id(${device_name}).turn_off();
            call.perform();
            #define Effect1 //Effect1
            #define Effect2 //Effect2
            #define Effect3 //Effect3
            #define Effect4 //Effect4
            static int effect = 1;
            call = id(${device_name_rgb}).turn_on();
            call.set_transition_length(500);
            switch(effect)
            {
            case 1: call.set_rgb(1.0, 0.0, 0.0);
            //call.set_effect(effect1);
                    break;
            case 2: call.set_rgb(1.0, 1.0, 0.0);
            //call.set_effect(effect2);
                    break;
            case 3: call.set_rgb(0.0, 1.0, 0.0);
            //call.set_effect(effect3);
                    break;
            case 4: call.set_rgb(0.0, 1.0, 1.0);
            //call.set_effect(effect4);
                    break;
            }
            effect++;
            if(effect == 5)
            {
              effect = 1;
            }
            call.perform();
            
  - platform: remote_receiver
    name: "RGB Colour Toggle Button"
    nec:
      address: 0xFF00
      command: 0x30CF
    on_press:
      then:
        - lambda: |-
            auto call = id(${device_name}).turn_off();
            call.perform();
            #define Color1 1.0, 0.0, 0.0 //Red
            #define Color2 1.0, 1.0, 0.0 //Yellow
            #define Color3 0.0, 1.0, 0.0 //Green
            #define Color4 0.0, 1.0, 1.0 //Cyan
            #define Color5 0.0, 0.0, 1.0 //Blue
            #define Color6 1.0, 0.0, 1.0 //Pink 
            static int color = 1;
            call = id(${device_name_rgb}).turn_on();
            call.set_transition_length(500);
            switch(color)
            {
            case 1: call.set_rgb(1.0, 0.0, 0.0);
                    break;
            case 2: call.set_rgb(1.0, 1.0, 0.0);
                    break;
            case 3: call.set_rgb(0.0, 1.0, 0.0);
                    break;
            case 4: call.set_rgb(0.0, 1.0, 1.0);
                    break;
            case 5: call.set_rgb(0.0, 0.0, 1.0);
                    break;
            case 6: call.set_rgb(1.0, 0.0, 1.0);
                    break;
            }
            color++;
            if(color == 7)
            {
              color = 1;
            }
            call.perform();
  - platform: remote_receiver
    name: "Warm Light Button"
    nec:
      address: 0xFF00
      command: 0x10EF
    id: warmbutton
    on_press:
      - while:
          condition:
            binary_sensor.is_on: warmbutton
          then:
            - lambda: |-
                float current_temp = id(${device_name}).current_values.get_color_temperature();
                auto call = id(${device_name}).turn_on();
                call.set_color_temperature(current_temp + 100);
                call.set_transition_length(1000); // in ms
                call.perform();
            - delay: 0.1s

  - platform: remote_receiver
    name: "Cold Light Button"
    nec:
      address: 0xFF00
      command: 0xE01F
    id: coldbutton
    on_press:
      - while:
          condition:
            binary_sensor.is_on: coldbutton
          then:
            - lambda: |-
                float current_temp = id(${device_name}).current_values.get_color_temperature();
                auto call = id(${device_name}).turn_on();
                call.set_color_temperature(current_temp - 100);
                call.set_transition_length(1000); // in ms
                call.perform();
            - delay: 0.1s

  - platform: remote_receiver
    name: "Bright+ Button"
    nec:
      address: 0xFF00
      command: 0xA05F
    id: brightbutton
    on_press:
      - while:
          condition:
            binary_sensor.is_on: brightbutton
          then:
            - light.dim_relative:
                id: "${device_name}"
                relative_brightness: 5%
                transition_length: 0.1s
            - delay: 0.1s


  - platform: remote_receiver
    name: "Dim- Button"
    nec:
      address: 0xFF00
      command: 0x609F
    id: dimbutton
    on_press:
      - while:
          condition:
            binary_sensor.is_on: dimbutton
          then:
            - light.dim_relative:
                id: "${device_name}"
                relative_brightness: -5%
                transition_length: 0.1s
            - delay: 0.1s

light:
  - platform: cwww
    name: ${friendly_name}    # Put the name that you want to see in Home Assistant.
    id: ${device_name}    # id used in esphome.
    cold_white: output_cold_white
    warm_white: output_warm_white
    cold_white_color_temperature: 6536 K
    warm_white_color_temperature: 2000 K
    constant_brightness: true
    default_transition_length: 1s
  - platform: rgb
    name: ${friendly_name_rgb}
    id: ${device_name_rgb}
    red: output_red
    green: output_green
    blue: output_blue
    default_transition_length: 0.5s
    restore_mode: RESTORE_DEFAULT_OFF

## TODO's remote_receiver on and off control both cwww and rgb toggle global int
## Brightness and colour change for rgb light

also trying to replicate effects as follows: -

Hope anyone can chime in would be great!!!

Ash

Updating my own post here: -

substitutions:
  device_ssid: "Dining Room Light"
  device_name: diningroomlight
  device_main_description: "RGBWW Ceiling LED light with RF remote located in Dining Room with discreet Tunable White & RGB Rear Light (shows up as separate lights)."
  device_description: Dining Room Light - Main Light
  friendly_name: "Dining Room Light - Tunable White"    # Put the name that you want to see in Home Assistant.
  device_name_rgb: diningroomlightrgb
  device_description_rgb: "Dining Room Light - RGB Rear."    # Put the name that you want to see in Home Assistant.
  friendly_name_rgb: "Dining Room Light RGB"
  frequency_rgb: 100 Hz
  frequency_cw: 250 Hz
  frequency_ww: 250 Hz

esphome:
  name: ${device_name}
  platform: ESP8266
  board: esp01_1m

wifi:
    ssid: !secret wifi_1st_ssid
    password: !secret wifi_1st_password

    # Enable fallback hotspot (captive portal) in case wifi connection fails
    ap:
      ssid: ${device_ssid}
      password: !secret ap_password

captive_portal:

# Enable logging
# Example configuration entry
debug:

# Logger must be at least debug (default)
logger:
  level: debug

# Enable Home Assistant API
api:
  password: !secret api_password

ota:
  password: !secret ota_password

web_server:
  port: 80


output:
  - platform: esp8266_pwm
    id: output_red
    pin: GPIO5
    max_power: 100%
    frequency: ${frequency_rgb}
  - platform: esp8266_pwm
    id: output_green
    pin: GPIO4
    max_power: 100%
    frequency: ${frequency_rgb}
  - platform: esp8266_pwm
    id: output_blue
    pin: GPIO14
    max_power: 100%
    frequency: ${frequency_rgb}
  - platform: esp8266_pwm
    id: output_cold_white
    max_power: 100%
    frequency: ${frequency_cw}
    pin: GPIO12
  - platform: esp8266_pwm
    id: output_warm_white
    pin: GPIO13
    max_power: 100%
    frequency: ${frequency_ww}

globals:
  - id: last_light_on
    type: int
    restore_value: no
    initial_value: '1'

remote_receiver:
  pin:
    number: GPIO2
    inverted: True
  dump: 
  - nec
#  tolerance: 20%
#  buffer_size: 1kB
#  filter: 2us
#  idle: 4ms

binary_sensor:
  - platform: remote_receiver
    name: "On Button"
    nec:
      address: 0xFF00
      command: 0xC03F
    id: onbutton
    on_press:
      then:
        - lambda: |-
            if(id(last_light_on) == 1)
            {
            auto call = id(${device_name}).turn_on();
            call.perform();
            }
            else if (id(last_light_on) == 2)
            {
            auto call = id(${device_name_rgb}).turn_on();
            call.perform();
            }
       
  - platform: remote_receiver
    name: Off Button"
    nec:
      address: 0xFF00
      command: 0x20DF
    on_press:
      then:
        - lambda: |-
            if(id(last_light_on) == 1)
            {
            auto call = id(${device_name}).turn_off();
            call.perform();
            }
            else if (id(last_light_on) == 2)
            {
            auto call = id(${device_name_rgb}).turn_off();
            call.perform();
            }

  - platform: remote_receiver
    name: "Night Mode Button"
    nec:
      address: 0xFF00
      command: 0x906F
    on_press:
      then:
        - lambda: |-
            auto call = id(${device_name_rgb}).turn_off();
            call.perform();
            call = id(${device_name}).turn_on();
            call.set_color_temperature(500); // in mireds
            call.set_brightness(0.08);
            call.set_transition_length(1000); // in ms
            call.perform();
        - delay: 0.1s

  - platform: remote_receiver
    name: "Main Light Button"
    nec:
      address: 0xFF00
      command: 0x50AF
    on_press:
        then:
        - lambda: |-
            auto call = id(${device_name_rgb}).turn_off();
            call.perform();
            #define cwwwmode1 100mireds //Cool White
            #define cwwwmode2 300mireds //Natural White
            #define cwwwmode3 500mireds //Warm WHite
            static int cwwwmode = 1;
            call = id(${device_name}).turn_on();
            call.set_transition_length(1000);
            switch(cwwwmode)
            {
            case 1: call.set_color_temperature(100);
                    break;
            case 2: call.set_color_temperature(300);
                    break;
            case 3: call.set_color_temperature(500);
                    break;
            }
            cwwwmode++;
            if(cwwwmode == 4)
            {
              cwwwmode = 1;
            }
            call.perform();
            
  - platform: remote_receiver
    name: "Mood Light Button"
    nec:
      address: 0xFF00
      command: 0xD02F
    on_press:
      then:
        - lambda: |-
            auto call = id(${device_name}).turn_off();
            call.perform();
            static int effect = 1;
            call = id(${device_name_rgb}).turn_on();
            call.set_transition_length(500);
            switch(effect)
            {
            case 1: call.set_effect("3 Colour Fade");
                    break;
            case 2: call.set_effect("strobe");
                    break;
            case 3: call.set_effect("My Custom Effect");
                    break;
            case 4: call.set_effect("My Custom Effect 2");
                    break;
            case 5: call.set_effect("None");
                    break;
            }
            effect++;
            if(effect == 6)
            {
              effect = 1;
            }
            call.perform();
            
  - platform: remote_receiver
    name: "RGB Colour Toggle Button"
    nec:
      address: 0xFF00
      command: 0x30CF
    on_press:
      then:
        - lambda: |-
            auto call = id(${device_name}).turn_off();
            call.perform();
            static int color = 1;
            call = id(${device_name_rgb}).turn_on();
            call.set_effect("None");
            call.set_transition_length(500);
            switch(color)
            {
            case 1: call.set_rgb(1.0, 0.0, 0.0);
                    break;
            case 2: call.set_rgb(1.0, 1.0, 0.0);
                    break;
            case 3: call.set_rgb(0.0, 1.0, 0.0);
                    break;
            case 4: call.set_rgb(0.0, 1.0, 1.0);
                    break;
            case 5: call.set_rgb(0.0, 0.0, 1.0);
                    break;
            case 6: call.set_rgb(1.0, 0.0, 1.0);
                    break;
            }
            color++;
            if(color == 7)
            {
              color = 1;
            }
            call.perform();

  - platform: remote_receiver
    name: "Warm Light Button"
    nec:
      address: 0xFF00
      command: 0x10EF
    id: warmbutton
    on_press:
      then:
        - lambda: |-
            if(id(last_light_on) == 1)
            {
            float current_temp = id(${device_name}).current_values.get_color_temperature();
            auto call = id(${device_name}).turn_on();
            call.set_color_temperature(current_temp + 100);
            call.set_transition_length(1000); // in ms
            call.perform();
            }
            else if (id(last_light_on) == 2)
            {
            float current_temp = id(${device_name_rgb}).current_values.get_color_temperature();
            auto call = id(${device_name_rgb}).turn_on();
            call.set_color_temperature(current_temp + 100);
            call.set_transition_length(1000); // in ms
            call.perform();
            }
        - delay: 0.01s

  - platform: remote_receiver
    name: "Cold Light Button"
    nec:
      address: 0xFF00
      command: 0xE01F
    id: coldbutton
    on_press:
      then:
        - lambda: |-
            if(id(last_light_on) == 1)
            {
            float current_temp = id(${device_name}).current_values.get_color_temperature();
            auto call = id(${device_name}).turn_on();
            call.set_color_temperature(current_temp - 100);
            call.set_transition_length(1000); // in ms
            call.perform();
            }
            else if (id(last_light_on) == 2)
            {
            float current_temp = id(${device_name_rgb}).current_values.get_color_temperature();
            auto call = id(${device_name_rgb}).turn_on();
            call.set_color_temperature(current_temp - 100);
            call.set_transition_length(1000); // in ms
            call.perform();
            }
        - delay: 0.01s

  - platform: remote_receiver
    name: "Bright+ Button"
    nec:
      address: 0xFF00
      command: 0xA05F
    id: brightbutton
    on_press:
      then:
        - lambda: |-
            if(id(last_light_on) == 1)
            {
            float brightness;
            auto call = id(${device_name}).turn_on();
            id(${device_name}).remote_values.as_brightness( &brightness );
            brightness += 0.1f;
            if( brightness > 1.0f )
            {
              brightness = 1.0f;
            }
            call.set_brightness( brightness );
            call.perform();
            }
            else if (id(last_light_on) == 2)
            {
            float brightness;
            auto call = id(${device_name_rgb}).turn_on();
            id(${device_name_rgb}).remote_values.as_brightness( &brightness );
            brightness += 0.1f;
            if( brightness > 1.0f )
            {
              brightness = 1.0f;
            }
            call.set_brightness( brightness );
            call.perform();
            }
        - delay: 0.01s

  - platform: remote_receiver
    name: "Dim- Button"
    nec:
      address: 0xFF00
      command: 0x609F
    id: dimbutton
    on_press:
      then:
        - lambda: |-
            if(id(last_light_on) == 1)
            {
            float brightness;
            auto call = id(${device_name}).turn_on();
            id(${device_name}).remote_values.as_brightness( &brightness );
            brightness -= 0.1f;
            if( brightness < 0.0f )
            {
              brightness = 0.0f;
            }
            call.set_brightness( brightness );
            call.perform();
            }
            else if (id(last_light_on) == 2)
            {
            float brightness;
            auto call = id(${device_name_rgb}).turn_on();
            id(${device_name_rgb}).remote_values.as_brightness( &brightness );
            brightness -= 0.1f;
            if( brightness < 0.0f )
            {
              brightness = 0.0f;
            }
            call.set_brightness( brightness );
            call.perform();
            }
        - delay: 0.01s

light:
  - platform: cwww
    name: ${friendly_name}    # Put the name that you want to see in Home Assistant.
    id: ${device_name}    # id used in esphome.
    cold_white: output_cold_white
    warm_white: output_warm_white
    cold_white_color_temperature: 6536 K
    warm_white_color_temperature: 2000 K
    constant_brightness: true
    default_transition_length: 1s
    on_turn_on:
    - globals.set:
        id: last_light_on
        value: '1'
  - platform: rgb
    name: ${friendly_name_rgb}
    id: ${device_name_rgb}
    red: output_red
    green: output_green
    blue: output_blue
    default_transition_length: 0.5s
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on:
    - globals.set:
        id: last_light_on
        value: '2'
    effects:
      - lambda:
          name: 3 Colour Fade
          update_interval: 0.25s
          lambda: |-
            static int state = 0;
            static int color_fade = 1;
            auto call = id(${device_name_rgb}).turn_on(); //put the id for your light in here
            call.set_transition_length(100);
            if (state == 0) 
            {
            call.set_brightness(0.09);
            
            }
            else if (state == 1)
            {
              switch(color_fade)
              {
                case 1: call.set_rgb(1.0, 0.0, 0.0);
                        break;
                case 2: call.set_rgb(0.0, 1.0, 0.0);
                        break;
                case 3: call.set_rgb(0.0, 0.0, 1.0);
                        break;
              }
              call.set_brightness(1.0);
            }
            state ++;
            if (state == 2){
            state = 0;
            }
            color_fade++;
            if(color_fade == 4)
            {
              color_fade = 1;
            }
            call.perform();
      - random:
          name: smooth
          transition_length: 4s
          update_interval: 5s
      - strobe:
          name: strobe
          colors:
            - state: True
              brightness: 80%
              red: 100%
              green: 90%
              blue: 0%
              white: 0%
              duration: 500ms
            - state: False
              duration: 250ms
            - state: True
              brightness: 80%
              red: 0%
              green: 100%
              blue: 0%
              white: 0%
              duration: 500ms
            - state: False
              duration: 250ms
            - state: True
              brightness: 80%
              red: 0%
              green: 100%
              blue: 60%  
              white: 0%
              duration: 500ms
      - flicker:
          name: flash
          alpha: 95%
          intensity: 1.5%
      - lambda:
          name: fade
          update_interval: 1s
          lambda: |-
            static int state = 0;
            auto call = id(${device_name_rgb}).turn_on();
            // Transtion of 1000ms = 1s
            call.set_transition_length(1000);
            if (state == 0) {
              call.set_rgb(1.0, 1.0, 1.0);
            } else if (state == 1) {
              call.set_rgb(1.0, 0.0, 1.0);
            } else if (state == 2) {
              call.set_rgb(0.0, 0.0, 1.0);
            } else {
              call.set_rgb(1.0, 0.0, 0.0);
            }
            call.perform();
            state += 1;
            if (state == 4)
              state = 0;
      - lambda:
          name: My Custom Effect
          update_interval: 1s
          lambda: |-
            static int state = 0;
            auto call = id(${device_name_rgb}).turn_on();
            // Transtion of 1000ms = 1s
            call.set_transition_length(1000);
            if (state == 0) {
              call.set_rgb(1.0, 1.0, 1.0);
            } else if (state == 1) {
              call.set_rgb(1.0, 0.0, 1.0);
            } else if (state == 2) {
              call.set_rgb(0.0, 0.0, 1.0);
            } else {
              call.set_rgb(1.0, 0.0, 0.0);
            }
            call.perform();
            state += 1;
            if (state == 4)
              state = 0;
      - lambda:
          name: My Custom Effect 2
          update_interval: 1s
          lambda: |-
            static int state = 0;
            auto call = id(${device_name_rgb}).turn_on();
            // Transtion of 1000ms = 1s
            call.set_transition_length(1000);
            if (state == 0) {
              call.set_rgb(1.0, 1.0, 1.0);
            } else if (state == 1) {
              call.set_rgb(0.5, 0.0, 1.0);
            } else if (state == 2) {
              call.set_rgb(0.0, 0.5, 1.0);
            } else {
              call.set_rgb(1.0, 0.0, 0.0);
            }
            call.perform();
            state += 1;
            if (state == 4)
              state = 0;

So heres the thing, using global variable I can get the RF remote to control both RGB and CWWW independently depending on which one was turned on last, unfortunately esphome does not implement hue controls or HS colour so I cannot change the colour unless that feature is added or I try to use the code from FastLED: - FastLED hsv2rgb.h and FastLED hsv2rgb.cpp, would really appreciate if someone could help me to do this?

Pretty much light is very close to stock functions, I require help copying the effects, I understand esphome has it’s own set of simple effects. My idea is for the uninitated they do not know difference between stock.

Can this be done in lambda, the on press dimming: -

- platform: remote_receiver
    name: "Bright+ Button"
    nec:
      address: 0xFF00
      command: 0xA05F
    id: brightbutton
    on_press:
      - while:
          condition:
            binary_sensor.is_on: brightbutton
          then:
            - light.dim_relative:
                id: diningroomlight
                relative_brightness: 5%
                transition_length: 0.1s
            - delay: 0.1s

Also does anyone know why esphome flickers when switching from 100% warm white to 100% cool white?

I’m including a link to the effects: -