Esphome time platform - how to switch on light with effects and brightness

Hi everyone, I have this code in esphome. The ESP board that I use is an ESP8266.

esphome:
name: candle
platform: ESP8266
board: nodemcuv2

wifi:
ssid: “ASUS_AP”
password: “redacted”

manual_ip:
static_ip: 192.168.3.150
gateway: 192.168.3.1
subnet: 255.255.255.0

ap:
ssid: “redacted”
password: “redacted”

captive_portal:

logger:

api:

ota:

light:

  • platform: monochromatic
    name: “Candle”
    id: candle
    output: candle_pwm
    default_transition_length: 0s
    effects:
    • flicker:
      name: Flicker
      alpha: 90%
      intensity: 5%

output:

  • platform: esp8266_pwm
    id: candle_pwm
    pin: GPIO2
    frequency: 1000 Hz

sensor:

  • platform: adc
    pin: VCC
    id: “VCC”
    internal: true
    name: “VCC Voltage”

  • platform: template
    name: “Candle battery level”
    unit_of_measurement: ‘%’
    update_interval: 5s
    lambda: |-
    return ((id(VCC).state /3.30) * 100.00);

time:

  • platform: sntp
    on_time:
    • seconds: 0
      minutes: 0
      hours: 17
      days_of_week: MON-SUN
      then:
      • light.turn_on: candle

The above code did validate without issues on esphome but the trouble is that I do not know how to turn on the light with the flicker effect and to also set a custom brightness to it.

In node-red I would just call the turn_on service and give it the following parameter:
{“effect”:“flicker”,“brightness”:178}

I googled but I could not find relevant hits how to integrate this flicker and brightness parameter to esphome.

Some help is greatly appreciated.

light.turn_on:
  id: candle
  effect: flicker

Thanks Nick! Didn’t expect the solution to be something so straightforward and yet I am stumbled by it.

It appears to compile and I am trying it out to see if it works. Will report back later.

Thanks again!

Hi Nick,

I couldn’t get this to work. Here is a subset of my code in ESPHome.

time:
  - platform: sntp
    on_time:
      - seconds: 0
        minutes: 0
        hours: 13
        days_of_week: MON-SUN
        then:
          - light.turn_on: 
              id: candle
              effect: flicker
              brightness: 70%

      - seconds: 0
        minutes: 0
        hours: 7
        days_of_week: MON-SUN
        then:
          - light.turn_off: 
              id: candle

In this sample code, essentially what I wanted to do is to switch on the light at 1pm and switch off the light at 7am.

There are no compile errors but the light is not switching on at the pre-determined time.

Any ideas?

Thanks

I’ve not used light controll inside ESPHome jet (why not in HA?). Are you sure, the esp has the correct current time set? You should be able to verify in the log.

If not, specify a time reference, for example home assistant, with

time:
  platform: homeassistant
  id: homeassistant_time

EDIT: I see, sntp uses public time servers. Wrong timezone?

EDIT2: According to documentation, the first day of the week is Sunday, so you might have to specify SUN-SAT. Why even bother, if it runs every day?

Thanks Sean. Yes I did have all the automations previously defined in node-red and it is working well. I then realized that esphome has built in automations, so I am just keen to try this out. It looks like this is a lot more complex than I initially thought.

I have got compile errors while setting the sntp time-zone and/or setting the time to homeassistant.

so I am giving up now and reverting back to automations using node-red.