Problems passing data from device to HA

Problems passing data to Home Assistant script

Hello all. Finishing up my project and I’m struggling with final coding pieces. Project is to provide a remote to allow my wife/kids to be able to send our robot vacuum without the app. The device has 6 inputs (rooms) and two buttons (one to send, one to stop). My project sees which rooms are high, and on send button press, will send a binary output to the HA script.

Below is my Vacuum controller yaml file as well as the HA script. My issue is when my controller send input data, my script never interprets which input is high but just says all are high. In the developer tools > Actions tab, when I pass the fields to my script my outputs are perfect. I think there’s a disconnect with my script and the yaml for the controller.

Thanks!


alias: Robot Vac Controller
description: Start Roborock cleaning selected rooms
fields:
  living_room:
    description: Living Room
    required: true
    example: false
  kitchen:
    description: Kitchen
    required: true
    example: false
  dining_room:
    description: Dining Room
    required: true
    example: false
  foyer:
    description: Front
    required: true
    example: false
  sunroom:
    description: Study Room
    required: true
    example: false
  piano_room:
    description: Pantry Room
    required: true
    example: false
sequence:
  - variables:
      segments: >-
        {% set room_map = {
          "living_room": 17,
          "kitchen": 16,
          "dining_room": 18,
          "foyer": 23,
          "piano_room": 20,
          "sunroom": 19
        } %}

        {% set data = namespace(selected=[]) %}

        {% if living_room %}{% set data.selected = data.selected +
        [room_map.living_room] %}{% endif %} {% if kitchen %}{% set
        data.selected = data.selected + [room_map.kitchen] %}{% endif %} {% if
        dining_room %}{% set data.selected = data.selected +
        [room_map.dining_room] %}{% endif %} {% if foyer %}{% set data.selected
        = data.selected + [room_map.foyer] %}{% endif %} {% if piano_room %}{%
        set data.selected = data.selected + [room_map.piano_room] %}{% endif %}
        {% if sunroom %}{% set data.selected = data.selected +
        [room_map.sunroom] %}{% endif %} {{ data.selected }}
  - action: notify.notify
    data:
      message: "{{ segments }}"


esphome:
  name: vacuum-controller
  friendly_name: vacuum controller

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

# Enable logging
logger:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: on
  ap:
    ssid: Robot Vac Hotspot
    password: "###"

ota:
  - platform: esphome
    password: "###"

captive_portal:

# LED stuff
output:
  - platform: gpio
    pin: GPIO4
    id: light_output

light:
  - platform: binary
    name: "Status LED"
    id: status_led
    output: light_output

# Input Switches
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
      mode: INPUT_PULLUP
      inverted: true
    name: "Living Room"
    id: living_room

  - platform: gpio
    pin:
      number: GPIO6
      mode: INPUT_PULLUP
      inverted: true
    name: "Kitchen"
    id: kitchen

  - platform: gpio
    pin:
      number: GPIO21
      mode: INPUT_PULLUP
      inverted: true
    name: "Piano Room"
    id: piano_room

  - platform: gpio
    pin: 
      number: GPIO7
      mode: INPUT_PULLUP
      inverted: true
    name: "Foyer"
    id: foyer

  - platform: gpio
    pin: 
      number: GPIO20
      mode: INPUT_PULLUP
      inverted: true
    name: "Dining Room"
    id: dining_room

  - platform: gpio
    pin:
      number: GPIO10
      mode: INPUT_PULLUP
      inverted: true
    name: "Sunroom"
    id: sunroom

# Buttons
  - platform: gpio
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
      inverted: true
    name: "Send Button"
    id: send_button
    on_press:
      then:
        - light.turn_on:
            id: status_led
        - delay: 2s
        - light.turn_off: status_led
        - homeassistant.service:
            service: script.handle_room_cleaning
            data:
              living_room: !lambda 'return id(living_room).state;'
              kitchen: !lambda 'return id(kitchen).state;'
              piano_room: !lambda 'return id(piano_room).state;'
              foyer: !lambda 'return id(foyer).state;'
              dining_room: !lambda 'return id(dining_room).state;'
              sunroom: !lambda 'return id(sunroom).state;'

  - platform: gpio
    pin:
      number: GPIO1
      mode: INPUT_PULLUP
      inverted: true
    name: "Stop Button"
    id: stop_button
    on_press:
      then:
        - light.turn_on: status_led
        - delay: 2s
        - light.turn_off: status_led
        - homeassistant.service:
            service: vacuum.stop
            data:
              entity_id: vacuum.roborock_s7_maxv

# Set LED to blue when connected to API
api:

  on_client_connected:
    then:
      - light.turn_on:
          id: status_led

  on_client_disconnected:
    then:
      - light.turn_off: status_led

What exactly are you using for all of these user inputs? You specified that 2 of them are buttons so, what kind of physical components are you using to select the specific rooms if they aren’t also buttons? I would assume those are also buttons but, you specifically mentioned only using 2 buttons so, this is a detail that’s very relevant here.

This is why clarification on the Inputs is important here. A common problem or cause of confusion I see a lot is people not distinguishing between physical buttons/switches, momentary or locking/latching and which Esphome Integration to use for that that type of button or switch and then wiring it to work as either a Active high or Active Low logic and since you’ve enabled internal pull-up resistors and Inverted the logic for all 6 Inputs, is it safe to assume you know how to wire them based on whether you want to use a logic High or logic Low that gets sent to the GPIO’s?

Either the wiring is backwards, wired wrong, or the buttons/switches have built in resistors that are causing all of them to consistently stay High and your unable to toggle them or possibly they are just configured wrong, it’s hard to know which reason without you also clarifying your wiring with a diagram, a photo, or even links to where you bought these buttons/switches…

It’s hard to really offer any helpful suggestions without fully understanding these physical inputs, the wiring, and if any and which ones are momentary buttons and if any of them are locking/latching switches or anything in between.

Thanks for the reply.

For the room inputs, I’m using a physical rocker/toggle switch. The switch’s have been tested in the code and function correctly. Similarly the buttons are simple keyboard stitches and have been tested in code and functions correctly. Attached are two photos (front and back) of the controller. From my debugging, I feel like the disconnect is with passing the inputs to HA. I’ve also tried putting the fields variables in {{}} and with various “” ‘’ without success.


Tested prior to installing them how they are currently?

Thats highly unlikely. Have you looked at the logs and verified each button is turning ON and Off when you toggle each button and switch and it’s showing that change in the log output?

Im wondering if your swiches are working how you think they are…

If they arent showing state changes in the log output as you press them, try removing the Inverted and pullup from a couple then flash it again and check the log.

Those buttons are simply killing the beauty or your nice switch board.
@Poo_on_myShoe can suggest you something reasonable.
While replacing them also post a simple wiring scheme of your circuit, it’s nearly impossible to debug from your image.

Obviously just kidding about esthetics…