Home Assistant rejecting a ESPHome homeassistant.service:

Here is my code where ${remote_id} is my entity in Home Assistant.

binary_sensor:
  - platform: gpio        # DEFINE ESP External On/Off button 
    name: ${esp_id} ON/OFF Button
    id: s1
    pin:
      number: D7
      mode:
        input: true
        pullup: true
      inverted: true
    filters:
    - delayed_on: 20ms      # debouncing 

    on_press:
      - logger.log:
          format: "${esp_id} ON/OFF Button : ON "             
          level: INFO
      - homeassistant.service:
          service: switch.turn_on
          data:
            entity_id: ${remote_entity}

I receive an error message in the log

Dev D1mini-06: Service call switch.turn_on: with data {'entity_id': 'switch.lampe_salon'} rejected; If you trust this device and want to allow access for it to make Home Assistant service calls, you can enable this functionality in the options flow

I cannot find anything about this rejection and how to avoid it in the ESPHome documentation homeassistant.service Action.

I found a way around it, using NodeRed I can call the service when Home Assistant identify that the button has been press.

However, I would prefer a direct service call to HA directly to eliminate on extra layer of processing (NodeRed) and simplify the maintenance.
Does it have to do with API encryption, mi connection is not encrytped.

1 Like

Do this.

It’s cryptic I know, but in HA, settings, Devices and Services, Integrations tab, select ESPHome. Click on CONFIGURE for the device you want to enable service calls and check the box: “Allow the device to make Home Assistant service calls”

This was introduced a couple of releases ago.

5 Likes

Thanks, got it to accept my service call.
Cryptic indeed! I think that this should be in the documentation.
I found documentation in ESPHome - Home Assistant
However, I think that it should also be documented in ESPHome also, Native API Component — ESPHome

This threw me fir a loop yesterday! I’ve been using esphome for years and have 50+ nodes with all kinds of service calls. I tried setting up a new wiegand26 keypad yesterday and service calls weren’t going through. I fiddled with it for 3 hours before I even checked the HA logs I’m not sure why they did this, it may have been a security risk but it seems like that change got slipped in without much chatter in the forums because I had no 8dea it was changed either.

Glad, I could help you to figure this out.

Still the case with the cryptic message. I’ll see if I can create a PR.