Arduino Port Expander

I followed this guide


to expand the gpio arduino to esp8266, in the hope of using an alarm system, the file has no errors but at the moment of loading I receive ERROR.
#allarme esphome - home assistant
#ws2812b
#led 1 sensore 1
#led 2 sensore 2
#led 3 stato connessione api con home assistant
#led 4 stato connessione wifi
#led 5 stato allarme armato/disarmato
#led 6 stato allarme triggered
#GPIO4  D2 display 16x2 sda
#GPIO5  D1 display 16x2 scl
#GPIO2  D4 led onboard stato esp
#GPIO14 D5 armed/disarmed to keypad arduino
#GPIO16 D0 pir/zona 1
#GPIO13 D7 pir/zona 2
#GPIO15 D8 buzzer
#GPIO12 D6 sirena
#GPIO0  D3 ws2812b led status


substitutions:
  alarm_code: "xxxxxxxxxx"
  disarmed_id: "0"
  pending_id: "1"
  triggered_id: "2"
  armed_home_id: "3"
  
esphome:
  name: antifurto_esp_expander_avr
  platform: ESP8266
  board: nodemcuv2
  includes:
      - arduino_port_expander.h

  # restore state
  # if trigger sequence reset to armed for now.
  #   should it retrigger sequence?
  on_boot:
    then:
      - lambda: |-
          if (id(state_int) == ${disarmed_id}) {
            id(alarm_condition).publish_state("disarmed");
          } else if (id(state_int) == ${pending_id}){
            id(alarm_condition).publish_state("armed_home");
            id(state_int) = ${armed_home_id};
          } else if (id(state_int) == ${triggered_id}){
            id(alarm_condition).publish_state("armed_home");
            id(state_int) = ${armed_home_id};
          } else if (id(state_int) == ${armed_home_id}){
            id(alarm_condition).publish_state("armed_home");
          } else{
            id(alarm_condition).publish_state("disarmed");
            id(state_int) = ${disarmed_id};
          }
      - light.turn_on: 
         id: my_light
      - delay: 3s
      - light.addressable_set:
          id: my_light
          range_from: 0
          range_to: 5
          red: 0%
          green: 0%
          blue: 0%
      - script.execute: boot_state 
     
wifi:
  ssid: "xxxxxxx"
  password: "xxxxxxxxxxx"
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Antifurto Nodemcu"
    password: "xxxxxxxxxxxxxxxx"
      
# Example configuration entry
web_server:
  port: 80
  
captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

 # add arm and disarm services to ha
 services:
    - service: arm_home
      variables:
         code: string
      then:
        - if:
            condition:
                 lambda: "return code == \"${alarm_code}\";"
            then:
              - script.execute: alarm_arm
        - if:
            condition:
                 lambda: "return id(pir_cucina).state;"
            then:
              - script.execute: trigger_alarm
        - if:
            condition:
                 lambda: "return id(pir_corridoio).state;"
            then:
              - script.execute: trigger_alarm
              
    - service: disarm
      variables:
         code: string
      then:
        - if:
            condition:
              lambda: "return code == \"${alarm_code}\";"
            then:
              - script.execute: alarm_disarm

ota:
# global for state restore
i2c:

- id: i2c_component
  sda: GPIO4
  scl: GPIO5
  scan: True
  
display:
  - platform: lcd_pcf8574
    dimensions: 16x2
    address: 0x27
    id: lcd
    lambda: |-
       it.strftime( "%H:%M %d.%m.%Y", id(my_time).now());
         if (id(state_int) == ${disarmed_id}) {
            it.print(0, 1,"Stato disarmato");
          } 
         if (id(state_int) == ${armed_home_id}) {
            it.print(0, 1,"Stato armato");
          } 
         if (id(state_int) == ${pending_id}) {
            it.print(0, 1,"Stato innescato");
          } 
         if (id(state_int) == ${triggered_id}) {
            it.print(0, 1,"Stato in allarme");
          } 
  
time:
- platform: sntp
  id: my_time
  
globals:
   - id: state_int
     type: int
     restore_value: yes
     initial_value: '0'

# Example configuration entrlight:
light:
  - platform: fastled_clockless
    chipset: WS2811
    pin: D3
    num_leds: 6
    internal: true
    rgb_order: GRB
    id: my_light
    name: "FastLED WS2811 Light"
              
sensor:
  - platform: uptime
    name: Uptime Sensor
    
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s
    
status_led:
  pin: GPIO2    

# define the port expander hub, here we define one with id 'expander1',
# but you can define many
custom_component:
  - id: expander1
    lambda: |-
      auto expander = new ArduinoPortExpander(i2c_component, 0x08, true);
      return {expander};
      
# define binary sensors, use the Arduino PIN number for digital pins and
# for analog use 14 for A0, 15 for A1 and so on...
binary_sensor:
  - platform: custom
    lambda: |-
      return {ape_binary_sensor(expander1, 7),
              ape_binary_sensor(expander1, 8),
              ape_binary_sensor(expander1, 9),
              ape_binary_sensor(expander1, 10),
              ape_binary_sensor(expander1, 14) // 14 = A0
              };

    binary_sensors:
      - id: arm_disarm
        internal: true # don't show on HA
        on_press:
          then:
           - if:
              condition:
                or: 
                - lambda: |-
                     return id(state_int) == ${pending_id};
                - lambda: |-
                     return id(state_int) == ${triggered_id};
                - lambda: |-
                     return id(state_int) == ${armed_home_id};
              then:
                - script.execute: alarm_disarm
              else:
                - script.execute: alarm_arm
                
      - id: pir_corridoio
        internal: true # don't show on HA
        on_state: 
          then:
            - if:
                condition:
                   binary_sensor.is_on: pir_cucina
                then:
                  - script.execute: trigger_alarm
            - if:
                condition:
                  - and:
                      binary_sensor.is_on: pir_cucina
                  - lambda: |-
                      
                then:
                  - light.addressable_set:
                      id: my_light
                      range_from: 1
                      range_to: 1
                      red: 50%
                      green: 50%
                      blue: 0%
            
            - if:
                condition:
                    - and:
                        binary_sensor.is_off: pir_cucina
                    - lambda: |-
                        return id(state_int) == ${disarmed_id};
                then:
                    - light.addressable_set:
                        id: my_light
                        range_from: 1
                        range_to: 1
                        red: 0%
                        green: 0%
                        blue: 0%
            - if:
                condition:
                    - and:
                       binary_sensor.is_on: pir_cucina
                    - lambda: |-
                        return id(state_int) == ${pending_id};
                then:
                    - light.addressable_set:
                        id: my_light
                        range_from: 1
                        range_to: 1
                        red: 50%
                        green: 50%
                        blue: 0%
      
      - id: pir_cucina
        internal: true # don't show on HA
        on_state: 
          then:
            - if:
                condition:
                     binary_sensor.is_on: pir_cucina
                then:
                  - script.execute: trigger_alarm
            - if:
                condition:
                  - and:
                       binary_sensor.is_on: pir_cucina
                  - lambda: |-
                       return  id(state_int) == ${disarmed_id};
                then:
                  - light.addressable_set:
                     id: my_light
                     range_from: 1
                     range_to: 1
                     red: 50%
                     green: 50%
                     blue: 0%
            
            - if:
                condition:
                  - and:
                       binary_sensor.is_off: pir_cucina
                  - lambda: |-
                       return id(state_int) == ${disarmed_id};
                then:
                  - light.addressable_set:
                     id: my_light
                     range_from: 1
                     range_to: 1
                     red: 0%
                     green: 0%
                     blue: 0%
            - if:
                condition:
                  - and:
                       binary_sensor.is_on: pir_cucina
                  - lambda: |-
                         return id(state_int) == ${pending_id};
                then:
                   - light.addressable_set:
                      id: my_light
                      range_from: 1
                      range_to: 1
                      red: 50%
                      green: 50%
                      blue: 0%
interval:
  - interval: 10s
    then:
     - if:
        condition:  
           wifi.connected:
        then:
           - light.addressable_set:
              id: my_light
              range_from: 3
              range_to: 3
              red: 0%
              green: 0%
              blue: 100%
        else:
           - light.addressable_set:
              id: my_light
              range_from: 3
              range_to: 3
              red: 0%
              green: 0%
              blue: 0%
     - if:
        condition:
          api.connected:
        then:
         - light.addressable_set:
            id: my_light
            range_from: 2
            range_to: 2
            red: 0%
            green: 0%
            blue: 100%
        else:
         - light.addressable_set:
            id: my_light
            range_from: 2
            range_to: 2
            red: 0%
            green: 0%
            blue: 0%
          
output:
  - platform: gpio
    pin: D8
    id: output_buzzer_front_door
    
  - platform: gpio
    pin: D6
    id: output_sirena

# warning chirp when pending
switch:
  - platform: template
    turn_on_action:
      - switch.template.publish:
          id: buzzer_front_door
          state: ON
      - while:
          condition:
            switch.is_on: buzzer_front_door
          then:
            - light.addressable_set:
                 id: my_light
                 range_from: 5
                 range_to: 5
                 red: 100%
                 green: 0%
                 blue: 0%
            - output.turn_on: output_buzzer_front_door
            - delay: 10ms
            - light.addressable_set:
                 id: my_light
                 range_from: 5 
                 range_to: 5
                 red: 0%
                 green: 0%
                 blue: 0%
            - output.turn_off: output_buzzer_front_door
            - delay: 990ms
    turn_off_action:
      - switch.template.publish:
          id: buzzer_front_door
          state: OFF
      - output.turn_off: output_buzzer_front_door
    id: buzzer_front_door

# holds alarm condition for arm/disarm/pending/triggered
text_sensor:
  - platform: template
    name: "Alarm Condition"
    id: "alarm_condition"
    
script:
  # when arming and disarming, turn off all sirens and buzzers
  # also, cancel any trigger sequence
  - id: alarm_arm
    then:
      - text_sensor.template.publish:
          id: alarm_condition
          state: "armed_home"
      - script.stop: trigger_alarm_execute
      - switch.turn_off: buzzer_front_door
      - output.turn_off: output_sirena
      - light.addressable_set:
         id: my_light
         range_from: 5 
         range_to: 5
         red: 0%
         green: 0%
         blue: 0%
      - light.addressable_set:
         id: my_light
         range_from: 4 
         range_to: 4
         red: 100%
         green: 0%
         blue: 0%
      - lambda: |-
          id(state_int) = ${armed_home_id};
          
  - id: alarm_disarm
    then:
      - text_sensor.template.publish:
          id: alarm_condition
          state: "disarmed"
      - script.stop: trigger_alarm_execute
      - switch.turn_off: buzzer_front_door
      - output.turn_off: output_sirena
      - lambda: |-
          id(state_int) = ${disarmed_id};
      - light.addressable_set:
         id: my_light
         range_from: 5 
         range_to: 5
         red: 0%
         green: 0%
         blue: 0%
      - light.addressable_set:
         id: my_light
         range_from: 4 
         range_to: 4
         red: 0%
         green: 100%
         blue: 0%
  # triggering sequence
  - id: trigger_alarm_execute
    then:
      - text_sensor.template.publish:
          id: alarm_condition
          state: "pending"
      - switch.turn_on: buzzer_front_door
      - lambda: |-
          id(state_int) = ${pending_id};
      - delay: 30s
      - text_sensor.template.publish:
          id: alarm_condition
          state: "triggered"
      - switch.turn_off: buzzer_front_door
      - output.turn_on: output_sirena
      - light.addressable_set:
          id: my_light
          range_from: 5
          range_to: 5
          red: 100%
          green: 0%
          blue: 0%
      - lambda: |-
          id(state_int) = ${triggered_id};
      - delay: 3600s
      # TODO: turn on siren
  # only execute triggering if armed and not already running
  - id: trigger_alarm
    then:
      if:
        condition:
          and:
            - not:
                script.is_running: trigger_alarm_execute
            - lambda: |-
                return id(state_int) == ${armed_home_id};
        then:
            script.execute: trigger_alarm_execute
            
  - id: boot_state        
    then:
       - if:
            condition:
             or:
              - lambda: |-
                 return id(state_int) == ${pending_id};
              - lambda: |-
                 return id(state_int) == ${triggered_id};
              - lambda: |-
                 return id(state_int) == ${armed_home_id};
            then:
              - light.addressable_set:
                 id: my_light
                 range_from: 4 
                 range_to: 4
                 red: 100%
                 green: 0%
                 blue: 0%
            else:
              - light.addressable_set:
                 id: my_light
                 range_from: 4 
                 range_to: 4
                 red: 0%
                 green: 100%
                 blue: 0%

Do not post screenshots of text!

Because there are problems. I look for the error not the discussion.

A picture:

  • is not visible unless I download it
  • is not searchable by people having a similar problem in future.

Nevertheless I did download it. I suggest you look in the esphome issues tracker.

The photo is an addition … The title and description I think is clear … Anyway I have not solved the problem … If I load the firmware example for port arduino expander it works … While integrated to my anti-theft firmware, it validates perfectly but at the moment the upload gives me that error. Thanks

Validation does not check your lambda code. Did the tracker issue on github help?

I have a problem with a node consisting of an esp01 and Arduino nano used as a gpio expander in i2c connection. Since I have binary sensors that I use as an alarm input, it happens that after some time the esp01 and Arduino stop communicating and therefore no longer receive inputs. the problem is solved only with a reset of the esp.

How long does it take to time out?

You could restart it regularly?

the timeout is default … I didn’t set it

How long does it take to go wrong?

I did not check carefully … cmq the reboot you say is needed if there is no wifi connection or to the server … the esp stops communicating with Arduino … from home assistant I always see it online

As I say, try restarting the esp when it stops communicating with the arduino. Or do it every 24 hours, or however often it is needed.

but i said i reboot to get it back operational … but i can’t have an alarm node you have to restart it. practically the esp is online but the Arduino gpio stop communicating their status. I’m trying with more adequate nutrition. let’s see I keep under test. thank you

Using this for many of my esphome’s, since custom component is deprecated need to change this.
Did already someone spent time on moving it to an external component?