sairon / esphome-nspanel-lovelace-ui

ESPHome component for NSPanel Lovelace UI
Other
126 stars 32 forks source link

Could not determine a constructor for the tag '!lambda' #6

Closed konceptnet closed 2 years ago

konceptnet commented 2 years ago

Im getting this error at line 60 of my esphome configuration file for my nspanel :

substitutions:
  devicename: nspanel-2
  friendly_devicename: NSPanel 2
  panel_recv_topic: "tele/home_affichage/RESULT"
  panel_send_topic: "cmnd/home_affichage/CustomSend"

esphome:
  name: $devicename

esp32:
  board: esp32dev

wifi:
  networks:
    ssid: !secret ssid_iot
    password: !secret ssid_psk
  use_address: !secret
# Logger. Disable the temperature sensor etc. to focus on the HMI development
logger:
  level: DEBUG
  logs:
    sensor: WARN
    resistance: WARN
    text_sensor: WARN
    ntc: WARN

ota:
  password: !secret ota_pwd
  safe_mode: true

# API. Add api_pwd to your secrets.yaml.
api:
  services:
    - service: upload_tft
      variables:
        url: string
      then:
        - lambda: |-
            id(nspanel).upload_tft(url);
    # Service to play a rtttl tone
  #  - service: play_rtttl
  #    variables:
  #      song_str: string
  #    then:
  #      - rtttl.play:
  #          #rtttl: !lambda "return song_str;"
    # Service to send a command directly to the display. Useful for testing
    - service: send_command
      variables:
        cmd: string
      then:
        - lambda: "id(nspanel).send_custom_command(cmd.c_str());"
    # Service to pusblish to mqtt used for refreshin the panel
    - service: publish_to_recv_topic
      variables:
        cmd: string
      then:
        - mqtt.publish:
            topic: $panel_recv_topic
            #Here is my line 60 and I got the same thing at rttl.play few line earlier
            payload: !lambda "return cmd;"
    # Service to send a command wake the screen
    - service: wake
      then:
        - lambda: 'id(nspanel).send_custom_command("wake");'
    # Service to send a command to show screensaver (some of the values are hardcoded)
    - service: show_screensaver
      then:
        - mqtt.publish:
            topic: $panel_recv_topic
            payload: '{"CustomRecv":"event,sleepReached,cardGrid"}'
    # Service to navigate to screen
    - service: navigate_to_page
      variables:
        page: string
      then:
        - mqtt.publish_json:
            topic: $panel_recv_topic
            payload: |-
              root["CustomRecv"] = "event,buttonPress2,navigate." + page + ",button";
    # Service to send a command disable screensaver
    - service: disable_screensaver
      then:
        - lambda: 'id(nspanel).send_custom_command("timeout~0");'
    # Service to send a command enabled screensaver
    - service: enable_screensaver
      then:
        - lambda: 'id(nspanel).send_custom_command("timeout~20");'
    # Service to send a command wake the screen
    - service: dim_0_to_100
      variables:
        intensity: string
      then:
        - lambda: 'id(nspanel).send_custom_command("dimmode~"+intensity+"~100");'
    # Service to send a command To show the screen of a specific like
    - service: show_entity
      variables:
        entity: string
        title: string
      then:
        - lambda: 'id(nspanel).send_custom_command("pageType~popupLight~" + title + "~" + entity);'
    # Service to send a command To show the screen of a specific like
    - service: notify_on_screensaver
      variables:
        line1: string
        line2: string
      then:
        - lambda: 'id(nspanel).send_custom_command("notify~" + line1 + "~" + line2);'
        - rtttl.play: "short:d=4,o=5,b=100:16e6"
    # Service to send a command To show the screen of a specific like
    # interaction of the buttons are on implemented yet
    - service: notify_fullscreen
      variables:
        title: string
        description: string
        button1: string
        button2: string
        time_secs: string
      then:
        # show notification screen
        - lambda: 'id(nspanel).send_custom_command("pageType~popupNotify");'
        # set values on notification screen
        # color defined as number created in binary and converted to decimal (rrrrggggbbbbaaaa)
        - lambda: 'id(nspanel).send_custom_command("entityUpdateDetail~id~"+ title + "~65535~" + button1 +"~3840~" + button2 + "~61440~" + description + "~65535~" + time_secs);'
        - rtttl.play: "scale_up:d=32,o=5,b=100:c,c#,d#,e,f#,g#,a#,b"

# Uart for the Nextion display
uart:
  tx_pin: 16
  rx_pin: 17
  baud_rate: 115200

# Functionality for the Nextion display
external_components:
  - source:
      type: git
      url: https://github.com/sairon/esphome-nspanel-lovelace-ui
      ref: dev
    components: [nspanel_lovelace]

mqtt:
  id: mqtt_client
  broker: !secret mqtt_host
  username: !secret mqtt_user
  password: !secret mqtt_password

nspanel_lovelace:
  id: nspanel
  mqtt_recv_topic: $panel_recv_topic
  mqtt_send_topic: $panel_send_topic

sensor:
  # Internal temperature sensor, adc value
  - platform: adc
    id: ntc_source
    pin: 38
    update_interval: 10s
    attenuation: 11db

  # Internal temperature sensor, adc reading converted to resistance (calculation)
  - platform: resistance
    id: resistance_sensor
    sensor: ntc_source
    configuration: DOWNSTREAM
    resistor: 11.2kOhm

  # Internal temperature sensor, resistance to temperature (calculation)
  - platform: ntc
    id: temperature
    sensor: resistance_sensor
    calibration:
      b_constant: 3950
      reference_temperature: 25°C
      reference_resistance: 10kOhm
    name: $friendly_devicename Temperature

output:
  # Buzzer for playing tones
  - platform: ledc
    id: buzzer_out
    pin:
      number: 21

# Rtttl function for buzzer
rtttl:
  id: buzzer
  output: buzzer_out

switch:
  # Physical relay 1
  - platform: gpio
    name: $friendly_devicename Relay 1
    id: relay_1
    pin:
      number: 22
    on_turn_on:
      # show a light on the panel when we swich on the light
      # - lambda: 'id(nspanel).send_custom_command("pageType~popupLight~[TITLE TO SHOW ON SCREEN]~[ENTITY NAME]");'
      - lambda: 'id(nspanel).send_custom_command("pageType~popupLight~Light 1~light.bed_light");'
    on_turn_off:
      # send to screensaver when switch off the light
      - mqtt.publish:
          topic: $panel_recv_topic
          payload: '{"CustomRecv":"event,sleepReached,cardGrid"}'

  # Physical relay 2
  - platform: gpio
    name: $friendly_devicename Relay 2
    id: relay_2
    pin:
      number: 19
    on_turn_on:
      # show a light on the panel when we swich on the light
      - lambda: 'id(nspanel).send_custom_command("pageType~popupLight~Light 2~light.bed_light2");'
    on_turn_off:
      # send to screensaver when switch off the light
      - mqtt.publish:
          topic: $panel_recv_topic
          payload: '{"CustomRecv":"event,sleepReached,cardGrid"}'

  # Turn screen power on/off. Easy way to configure the screen power control, but this should not be used from HA, as all components must be re-initialized afterwards. For lights, names of lights etc. this practically means that the state must change once to happen.
  - platform: gpio
    name: Screen Power
    id: screen_power
    entity_category: config
    pin:
      number: 4
      inverted: true
    restore_mode: ALWAYS_ON

# Binary sensors
binary_sensor:
  # Left button below the display
  - platform: gpio
    name: $friendly_devicename Left Button
    pin:
      number: GPIO14
      inverted: true
    id: left_button
    on_press:
      then:
        - switch.turn_on: relay_1

  # Right button below the display
  - platform: gpio
    name: $friendly_devicename Right Button
    pin:
      number: GPIO27
      inverted: true
    id: right_button
    on_press:
      then:
        - switch.toggle: relay_2
sairon commented 2 years ago

I have fixed the syntax in your original post but I was not able to reproduce that error. Had to change all !secret occurrences to dummy values though - I suggest you to check if that's not somehow causing it.

But since the error doesn't seem to be anyhow related to ESPHome NSPanel component, I suggest you to create a minimal example that reproduces the case and report it in https://github.com/esphome/issues - it should at least get a better traction there.