Turn on light on NodeMCU with a button on another ESP-01

I hope I am just over-thinking this…

Have a NodeMCU with 4 MOSFET modules attached. The “lights” all show up in HA and I can turn them on and off in HA.

  - platform: esp8266_pwm
    pin: 5
    frequency: 100 Hz
    id: m1dim1

  - platform: esp8266_pwm
    pin: 4
    frequency: 100 Hz
    id: m1dim2

  - platform: esp8266_pwm
    pin: 14
    frequency: 100 Hz
    id: m1dim3

  - platform: esp8266_pwm
    pin: 12
    frequency: 100 Hz
    id: m1dim4

  - platform: monochromatic
    output: m1dim1
    name: "Module 1 Dimmer 1"
    id: m1dim1x

  - platform: monochromatic
    output: m1dim2
    name: "Module 1 Dimmer 2"
    id: m1dim2x

  - platform: monochromatic
    output: m1dim3
    name: "Module 1 Dimmer 3"
    id: m1dim3x

  - platform: monochromatic
    output: m1dim4
    name: "Module 1 Dimmer 4"
    id: m1dim4x

On a separate ESP-01 I have a single push-button that I want to press to turn on one of the “lights” on the NodeMCU.

  - platform: gpio
      number: GPIO0
      inverted: True
      mode: INPUT_PULLUP
    id: switch1x
    name: "Switch1x"
        - light.toggle: m1dim1x  

I get the following error on this code:
"Couldn’t find ID ‘m1dim1x’. Please check you have defined an ID with that name in your configuration.

What am I missing? Why can’t the ESP-01 code reference the ID of the light on the NodeMCU?

Because the reference is local.

Ideally use an automation in homeassistant

  platform: state
  entity_id: YOUR_BUTTON
  service: light.toggle
  entity_id: YOUR_LIGHT
1 Like

As far as I know, you cant do operations between different esphome devices directly. Either register a service to be called from home assistant inside the light node and execute this service on the esp01 or you have to use an automation in home assistant.

Well AFAIK you can set up the web server on the esp to be controlled, which creates a REST interface, then use the http request component on the controlling esp.

Hi Marc,

I used the idea of using an automation and it certainly worked. Oddly I had to restart my HA service for the automation to work (seems odd).

- id: '1607866854330'
  alias: Toggle m1dim1x
  description: ''
  - platform: state
    entity_id: binary_sensor.switch1x
    to: 'on'
  condition: []
  - type: toggle
    device_id: 66ecf16246c8a5f733e9c6e6d7947338
    entity_id: light.module_1_dimmer_1
    domain: light
  mode: single

I am looking to make this button have additional functionality. (Haven’t tried yet, just wanted to respond that your suggestion was helpful)

Single press - Toggles light on/off
Press and hold - dims light from current set point down to off. (like the set_relative function works)

It’s probably obvious that I am very new to HA/ESPHome. I really appreciate the help.

1 Like

I’m really new to HA/ESPHome. Can you point me to an example of registering a service in a node? I looked through the docs and found some info, but I don’t think I’m searching for the correct terms.

I looked at doing that but the web server service uses a lot of memory. I had low memory issues on the ESP-01 and OTA updating when I first started using ESPHome. Removing the web server function resolved that.

I’m sure that I could do that on the NodeMCU’s, but I’d like to have the same solution for every device.

Thanks for the input!

In the situation you described you don’t need to run web server on the esp-01.

Heres an example how to do it, i use it to have service calls instead of switches for my amplifier, which gets controlled through IR, which behave strangely.

  password: 'hereGoesYourAdvertLol'
    - service: vol_up
        - remote_transmitter.transmit_nec:
           address: 0x1D00
           command: 0xD926
    - service: vol_down
        - remote_transmitter.transmit_nec:
            address: 0x1D00
            command: 0x59A6

after the then: line there goes your actions that you want to execute. Theres even a possibility to make use of service data like a disired color for an rgb light, a fade out time and so on.


Boom! Thank you!

That makes total sense now. I added this to my node with the light:

    - service: m1dim1_on
        - light.toggle: m1dim1x

And this to my node with my button.

        - homeassistant.service:
            service: esphome.nodemcu03_m1dim1_on

Makes sooooo much sense now.

Thanks again for the guidance!