Weird Problem: Text not updating from HA sensors, all other sensor are fine

What is that integration?

This is just a hardcoded test sensor. What I am actually trying to do is send schedule information from the hacs schedule component. But to do that I need to send a csv text string. But I simplified the code to explain the problem
Thanks

Are you trying to implement the use of input text? That would be something like this:

input_text:
  bschet:
    name: Test text
    initial: Hello Test

I have never heard of that integration. I think you have made that up.

Its a custom card and custom component Scheduler card/custom component
I want to use it to define a schedule for the esp device that controls my biomass plant room. So the ESP needs to know the schedule so if I have a wifi or HA failure the controller still works

I have already set up the input helper via the gui that did help either that what drive input_text.text1

What does sensor.bschet say in developer tools/states.

The HA sensors sensor.bschet & input_text.text1 have right values but when I followed mike’s advice post #2 and published the ESP values back to HA both ESP values where unknown when the device was on and unavailable when the device was switch off.
I am going try to remove the ESP device from HA and re add it. Another post with a similar issue said it resolved it.

That did not resolve the issue :frowning_face:
Any other thoughts?
How do I get detailed logs from HA? Just clutching at straws

I get the feeling that you have probably changed a few things now, can you post:

  1. your esphome yaml
  2. any relevant ha yaml
  3. your esphome logs

This is the esp device yaml

esphome:
  name: boiler-control
  platform: ESP8266
  board: d1_mini
  on_boot:
    then:
      # read the RTC time once when the system boots
      ds1307.read_time:
  
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true


        

api:
  password: !secret api_password
  services:
    - service: update_nextion
      then:
        - lambda: 'id(disp1)->upload_tft();'

ota:
  password: !secret ota_password

logger:
    baud_rate: 0     # Disable UART logging (pins GPIO1/3 are used for Nextion communication)
    # Enable fallback hotspot (captive portal) in case wifi connection fails
    level: VERY_VERBOSE
    logs: 
        api: VERY_VERBOSE
        homeassistant: VERY_VERBOSE
        nextion: VERY_VERBOSE
        api.service: VERY_VERBOSE
        sensor: VERY_VERBOSE
        scheduler: DEBUG




captive_portal:
  

uart:
  rx_pin: D6 
  tx_pin: D7 
  baud_rate: 115200

time:
  - platform: ds1307
    id: rtc_time
    # repeated synchronization is not necessary unless the external RTC
    # is much more accurate than the internal clock
    update_interval: never
  - platform: homeassistant
    # instead try to synchronize via network repeatedly ...
    on_time_sync:
      then:
        # ... and update the RTC when the synchronization was successful
        ds1307.write_time:
http_request:
i2c:
  sda: D2
  scl: D1
  scan: true
dallas:
  - pin: D4
    update_interval: 30s
sensor:
  - platform: dallas    
    name: "Tank Top Temperature"
    address: 0x8C01202253CD1E28
    id: toptemp
 
    
  - platform: homeassistant
    id: sun_elevation
    entity_id: sensor.sun_elevation
    internal: true
    
  - platform: homeassistant   # Office temperature
    id: temperature_office
    entity_id: sensor.office_temperature_temperature
    internal: true
    
  - platform: wifi_signal
    name: "WiFi Signal Boiler"
    update_interval: 60s
    id: wifi_boiler

text_sensor:
  - platform:  homeassistant
    entity_id:  sensor.bschet
    name: "esp bsched rtn"
    id: bsched
    on_value:
      then:
        - lambda: |-
            ESP_LOGD("main", "The current schedba is %s", x.c_str());
            
  - platform: homeassistant
    name: "esp input test rtn"
    entity_id: input_text.text1
    id: input_text1
    on_value:
       then:
         - lambda:  ESP_LOGD("main", "The current schedbb is %s", x.c_str());
         
  - platform: template
    id: bscheda
    internal: true
    lambda: |-
      return {"Hello World"};
    update_interval: 60s   

    



# Select setup
select:
  - platform: template
    name: "Boiler State"
    id: boil_mode
    optimistic: true
    options:
      - 'Off'
      - 'Manual On'
      - 'Auto'
      - 'Local'
    initial_option: 'Off'
    on_value:
      then:
        - logger.log:
            format: "$$$$$$$$$$$$$$$ Chosen option: %s"
            args: ["x.c_str()"]
        - script.execute: adjust_buttons_pagew
        - script.execute: adjust_buttons_pageb
        
       
             
globals:
 - id: first_page             # First page of the display?
   type: bool
   restore_value: no
   initial_value: 'false'
   
 - id: current_brightness             # Is display on?
   type: float
   restore_value: no
   initial_value: '-1.0'
   
 - id: wifi_state
   type: bool
   restore_value: no
   initial_value: 'false'
   
 - id: current_mode          #  0= OFF, MAN_ON, AUTO,   = LOCAL
   type: int
   initial_value: '0'
   restore_value: yes
  
 - id: run_state                #  false not runing - true running
   type: bool
   restore_value: no
   initial_value: 'false'
   
 - id:  auto_btn_img_idx
   type: int
   restore_value: no
   initial_value: '0'
   
display:
  - platform: nextion
    id: disp1
    update_interval: 10s
    tft_url: 'http://rhome:8123/local/boiler5.tft'
    
    lambda: |-
      ESP_LOGD("main", "enter display loop");
      if (id(first_page)) {
        it.goto_page("weather");
        auto time = id(rtc_time).now();
         auto day_text =  time.strftime("%a");
         it.set_component_text("dayw",day_text.c_str());
         it.set_component_text_printf("hourw","%02d:",time.hour);
         it.set_component_text_printf("minutew","%02d",time.minute);
         it.set_component_text_printf("statuslabelw","s: %s",id(bsched).state.c_str());
         id(adjust_buttons_pagew).execute();
         if (id(wifi_state)) {
            it.send_command_printf  ("wifiiconw.picc=0");
         }
            else {
              it.send_command_printf  ("wifiiconw.picc=1");
            }

      } 
        else 
      {
        it.goto_page("temperature");
      
        it.set_component_text_printf("topt","%2.1f",id(toptemp).state);
        it.set_component_text_printf("bottemp","%2.1f",id(temperature_office).state);
        it.set_component_text_printf("ladtemp","%2.1f",id(temperature_office).state);
        it.set_component_text_printf("furtemp","%2.1f",id(temperature_office).state);
        it.set_component_text_printf("rettemp","%2.1f",id(temperature_office).state);
        it.set_component_text_printf("blendtemp","%2.1f",id(toptemp).state);
        it.set_component_text_printf("statuslabel","s: %s",id(bsched).state.c_str());
    
        
         auto time = id(rtc_time).now();
         auto day_text =  time.strftime("%a");
         it.set_component_text("day",day_text.c_str());
         it.set_component_text_printf("hour","%02d:",time.hour);
         it.set_component_text_printf("minute","%02d",time.minute);
          id(adjust_buttons_pageb).execute();
         if (id(wifi_state)) {
            it.send_command_printf  ("wifiicon.picc=0");
         }
            else {
              it.send_command_printf  ("wifiicon.picc=1");
            }
      }
     
      id(first_page) = !id(first_page);  // Switch page
      ESP_LOGD("main", "EXIT display loop");
      ESP_LOGD("main", "The current sched is %s", id(bsched).state.c_str());
      

binary_sensor:    
  - platform: status
    name: "Boiler Status"
    id: boiler_status
    
    
  - platform: nextion
    page_id: 0
    component_id: 14
    id: off_btn 
    name: "Set Off"
    internal: true
    on_release:
      lambda: |-
         auto call = id(boil_mode).make_call();
         call.set_option("Off");
         call.perform();

          

  - platform: nextion
    page_id: 0
    component_id: 15
    id: man_btn 
    name: "Set Manual"
    internal: true
    on_release:
      lambda: |-
         auto call = id(boil_mode).make_call();
         call.set_option("Manual On");
         call.perform();

           
  - platform: nextion
    page_id: 0
    component_id: 16
    id: auto_btn 
    name: "Set Auto"
    internal: true
    on_release:
     if:
          condition:
              lambda: 'return id(wifi_state);'
          then:
            lambda: |-
             auto call = id(boil_mode).make_call();
             call.set_option("Auto");
             call.perform(); 
          else:
            lambda: |-
             auto call = id(boil_mode).make_call();
             call.set_option("Local");
             call.perform();        
         

  - platform: nextion
    page_id: 1
    component_id: 9
    id: off_btnw 
    name: "Set Offw"
    internal: true
    on_release:
      lambda: |-
         auto call = id(boil_mode).make_call();
         call.set_option("Off");
         call.perform();

          

  - platform: nextion
    page_id: 1
    component_id: 8
    id: man_btnw 
    name: "Set Manualw"
    internal: true
    on_release:
      lambda: |-
         auto call = id(boil_mode).make_call();
         call.set_option("Manual On");
         call.perform();

           
  - platform: nextion
    page_id: 1
    component_id: 10
    id: auto_btnw 
    name: "Set Autow"
    internal: true
    on_release:
      if:
          condition:
              lambda: 'return id(wifi_state);'
          then:
            lambda: |-
             auto call = id(boil_mode).make_call();
             call.set_option("Auto");
             call.perform(); 
          else:
            lambda: |-
             auto call = id(boil_mode).make_call();
             call.set_option("Local");
             call.perform();        
         
  - platform: status
    id: apistatus
    name: "Boiler API Status"
    internal: true
    
    on_state:       # based on wifi connection, we set the global variable here. This way it will be stored and valid upon refresh
      - if:
          condition:
            api.connected:
          then: 
            - globals.set:
                id: wifi_state
                value: 'true'  
            - lambda: |-
                  id(disp1).send_command_printf  ("wifiicon.picc=0");
              
          else:
             - globals.set:
                 id: wifi_state
                 value: 'false' 
             - lambda: |-
                   id(disp1).send_command_printf  ("wifiicon.picc=1");
script:
  - id: adjust_buttons_pageb    # adjust button setting on boiler page
    then:
      - lambda: |-
          id(auto_btn_img_idx) = 0;
          if ( !id(wifi_state))
                id(auto_btn_img_idx) = 3;
           
          
      - if:
          condition:
             - lambda: |- 
                  return (strcmp( id(boil_mode).state.c_str(), "Off") == 0);
          then:
                lambda: |-
                  id(disp1).send_command_printf  ("off_btn.picc=1");
                  id(disp1).send_command_printf  ("man_btn.picc=0");
                  id(disp1).send_command_printf  ("auto_btn.picc=%i", id(auto_btn_img_idx));
      - if:
           condition:
            - lambda: |- 
                return (strcmp( id(boil_mode).state.c_str(), "Manual On") == 0);
           then:
            lambda: |-
              id(disp1).send_command_printf  ("off_btn.picc=0");
              id(disp1).send_command_printf  ("man_btn.picc=1");
              id(disp1).send_command_printf  ("auto_btn.picc=%i", id(auto_btn_img_idx));
      - if:
           condition:
            - lambda: |- 
                return (strcmp( id(boil_mode).state.c_str(), "Auto") == 0);
           then:
            lambda: |-
              id(disp1).send_command_printf  ("off_btn.picc=0");
              id(disp1).send_command_printf  ("man_btn.picc=0");
              id(disp1).send_command_printf  ("auto_btn.picc=1");
      - if:
           condition:
            - lambda: |- 
                return (strcmp( id(boil_mode).state.c_str(), "Local") == 0);
           then:
            lambda: |-
              id(disp1).send_command_printf  ("off_btn.picc=0");
              id(disp1).send_command_printf  ("man_btn.picc=0");
              id(disp1).send_command_printf  ("auto_btn.picc=2");
 
              
  - id: adjust_buttons_pagew      # adjust button setting on weather  page
    then:
      - lambda: |-
          id(auto_btn_img_idx) = 0;
          if ( !id(wifi_state))
                id(auto_btn_img_idx) = 3;

      - if: 
          condition:
             - lambda: |- 
                  return (strcmp( id(boil_mode).state.c_str(), "Off") == 0);
          then:
                lambda: |-
                  id(disp1).send_command_printf  ("off_btnw.picc=1");
                  id(disp1).send_command_printf  ("man_btnw.picc=0");
                  id(disp1).send_command_printf  ("auto_btnw.picc=%i",  id(auto_btn_img_idx));
        
      - if:
           condition:
            - lambda: |- 
                return (strcmp( id(boil_mode).state.c_str(), "Manual On") == 0);
           then:
            lambda: |-
              id(disp1).send_command_printf  ("off_btnw.picc=0");
              id(disp1).send_command_printf  ("man_btnw.picc=1");
              id(disp1).send_command_printf  ("auto_btnw.picc=%i", id(auto_btn_img_idx));
      - if:
           condition:
            - lambda: |- 
                return (strcmp( id(boil_mode).state.c_str(), "Auto") == 0);
           then:
            lambda: |-
              id(disp1).send_command_printf  ("off_btnw.picc=0");
              id(disp1).send_command_printf  ("man_btnw.picc=0");
              id(disp1).send_command_printf  ("auto_btnw.picc=1");
    
      - if:
           condition:
            - lambda: |- 
                return (strcmp( id(boil_mode).state.c_str(), "Local") == 0);
           then:
            lambda: |-
              id(disp1).send_command_printf  ("off_btnw.picc=0");
              id(disp1).send_command_printf  ("man_btnw.picc=0");
              id(disp1).send_command_printf  ("auto_btnw.picc=2");
   

HA config


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
logger:
  default: info
# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# Example configuration.yaml entry
sensor:  

  - platform: systemmonitor
    resources:
    - type: processor_use
    - type: disk_use_percent
      arg: "/"
    - type: disk_free
      arg: "/"
    - type: memory_use_percent
    - type: network_in
      arg: eth0
    - type: throughput_network_in
      arg: eth0
    - type: network_out
      arg: eth0
    - type: throughput_network_out
      arg: eth0
    - type: processor_temperature
    - type: last_boot
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'
# OPTIONAL CPU Raspberry Pi Temp
  - platform: command_line
    name: CPU Temp
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(2)  }}'


  - platform: mqtt
    name: "Temperature Test"
    unique_id: 'tempTestEnt'
    state_topic: "pi/sensor1"
    unit_of_measurement: "°C"
    value_template: "{{ value_json.temperature }}"

  - platform: template
    sensors:
        thermostat_status:
          friendly_name: 'HVAC Status'
          unique_id: 'sensor.hstatus'
          value_template: "{{ states.climate.office_trv.attributes.system_mode }}"    

        test_txt_sensor:
          friendly_name: 'Test Text'
          unique_id: 'sensor.bschet'
          value_template: 'Hello Test'

   
        schedule_5268b9:
          friendly_name: 'Boiler Schedule'
          unique_id: 'sensor.bsched'
          value_template: '{{ states.switch.schedule_5268b9.attributes.next_trigger }}'

switch:
  - platform: mqtt
    unique_id: pi_test_switch
    name: "Switch Test"
    state_topic: "pi/switch1/stat"
    value_template: "{{ value_json.status }}"
    command_topic: "pi/switch1/cmmd"
    payload_on: '{"status": "on"}'
    payload_off: '{"status": "off"}'
    state_on: 'on'
    state_off: 'off'
    optimistic: false
    qos: 0
    retain: false

Link to the logs as they are to big for the board
Logs

Thank you for help
I will setup a new device today with minimal code to see if its device code based or it is server side
Cheers

Paul

Right I have now set up a new device with minimal code/config. The same behaviour is seen. Text sensors from HA are not received by the device but text values set by the device are seen in HA. The code has a pair of timers one just prints the values from the sensors. The other timer forces a value into one of the sensors. HA reports both sensor as unknown until the force event happens. Other HA sensors (FLoat / Binary) are fine and rxed by device. The bottom line is home assistant text based sensor values are not sent from HA.
@nickrout As this looks like a native API issue how do I workout if the problem is HA or ESPHome. Are there any apps that use the native API so I can binary spilt the problem as at the moment not sure where to look . Was thinking about rolling ESPhome back to a earlier version

ESP code

# This is ESPHome configuration file. This goes to the esphome folder
# You need to provide your WiFi ssis/password and passwords for API and OTA (or put them in your esphome/secrets.yaml)
esphome:
  name: display_weather
  platform: ESP8266
  board: d1_mini
  
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true

api:
  password: !secret api_password
  

ota:
  password: !secret ota_password

logger:
    baud_rate: 0     # Disable UART logging (pins GPIO1/3 are used for Nextion communication)
    # Enable fallback hotspot (captive portal) in case wifi connection fails
    level: VERY_VERBOSE
    logs: 
        api: VERY_VERBOSE
        homeassistant: VERY_VERBOSE
        api.service: VERY_VERBOSE
        sensor: VERY_VERBOSE
        scheduler: DEBUG


time:
  - platform: sntp
    id: sntp_time
    on_time:
      # Every 15 seconds
      - seconds: /15
        
        then:
          - lambda: |-
                std::string val = id(bsched).state;
                ESP_LOGD("main", "The current bsched is %s", val.c_str());
                val = id(input_text1).state;
                ESP_LOGD("main", "The current input_text1 is %s", val.c_str());
      
          # Every1 minutes
      - seconds: /30
        minutes: /2
        then:
            - lambda: |-
                  std::string val = id(bsched).state;
                  id(bsched).publish_state("ESP forced value");
                  ESP_LOGD("main", "Forcing current input_text1");

                
sensor:
 
  - platform: homeassistant   # Office temperature
    id: temperature_office
    entity_id: sensor.office_temperature_temperature
    internal: true
    
text_sensor:
  - platform:  homeassistant
    entity_id:  sensor.bschet
    name: "esp bsched rtn"
    id: bsched
    on_value:
      then:
        - lambda: |-
            ESP_LOGD("main", "The current schedba is %s", x.c_str());
            
  - platform: homeassistant
    name: "esp input test rtn"
    entity_id: input_text.text1
    id: input_text1
    on_value:
       then:
         - lambda:  ESP_LOGD("main", "The current input_text1 is %s", x.c_str());

  - platform: template
    name: "esp template test rtn"
    id: bscheda
    lambda: |-
      return {"Hello World"};
    update_interval: 60s       

Log data

INFO Reading configuration /config/display_weather.yaml...
WARNING 'display_weather': Using the '_' (underscore) character in the hostname is discouraged as it can cause problems with some DHCP and local name services. For more information, see https://esphome.io/guides/faq.html#why-shouldn-t-i-use-underscores-in-my-device-name
INFO Detected timezone 'Etc/UTC'
INFO Generating C++ source...
INFO Compiling app...
Processing display_weather (board: d1_mini; framework: arduino; platform: platformio/espressif8266 @ 2.6.3)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
RAM:   [====      ]  44.0% (used 36056 bytes from 81920 bytes)
Flash: [====      ]  37.6% (used 392224 bytes from 1044464 bytes)
========================= [SUCCESS] Took 3.83 seconds =========================
INFO Successfully compiled program.
INFO Resolving IP address of display_weather.local
INFO  -> 192.168.1.98
INFO Uploading /config/.esphome/build/display_weather/.pioenvs/display_weather/firmware.bin (396384 bytes)
INFO Compressed to 273848 bytes
Uploading: [============================================================] 100% Done...

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from display_weather.local using esphome API
WARNING Can't connect to ESPHome API for display_weather.local: Error resolving IP address: [Errno -2] Name or service not known
INFO Trying to reconnect to display_weather.local in the background
INFO Successfully connected to display_weather.local
[17:27:21][I][app:102]: ESPHome version 2022.1.2 compiled on Jan 26 2022, 17:24:25
[17:27:21][C][wifi:488]: WiFi:
[17:27:21][C][wifi:350]:   Local MAC: 44:17:93:1E:29:0D
[17:27:21][C][wifi:351]:   SSID: [redacted]
[17:27:21][C][wifi:352]:   IP Address: 192.168.1.98
[17:27:21][C][wifi:354]:   BSSID: [redacted]
[17:27:21][C][wifi:355]:   Hostname: 'display_weather'
[17:27:21][C][wifi:357]:   Signal strength: -74 dB ▂▄▆█
[17:27:21][C][wifi:361]:   Channel: 12
[17:27:21][C][wifi:362]:   Subnet: 255.255.255.0
[17:27:21][C][wifi:363]:   Gateway: 192.168.1.254
[17:27:21][C][wifi:364]:   DNS1: 192.168.1.64
[17:27:21][C][wifi:365]:   DNS2: 192.168.1.254
[17:27:21][C][logger:233]: Logger:
[17:27:21][C][logger:234]:   Level: VERY_VERBOSE
[17:27:21][C][logger:235]:   Log Baud Rate: 0
[17:27:21][C][logger:236]:   Hardware UART: UART0
[17:27:21][C][logger:238]:   Level for 'api': VERY_VERBOSE
[17:27:21][C][logger:238]:   Level for 'homeassistant': VERY_VERBOSE
[17:27:21][C][logger:238]:   Level for 'api.service': VERY_VERBOSE
[17:27:21][C][logger:238]:   Level for 'sensor': VERY_VERBOSE
[17:27:21][C][logger:238]:   Level for 'scheduler': DEBUG
[17:27:21][C][template.text_sensor:021]: Template Sensor 'esp template test rtn'
[17:27:21][C][ota:082]: Over-The-Air Updates:
[17:27:21][C][ota:083]:   Address: display_weather.local:8266
[17:27:21][C][ota:086]:   Using Password.
[17:27:21][C][api:134]: API Server:
[17:27:21][C][api:135]:   Address: display_weather.local:6053
[17:27:21][C][api:139]:   Using noise encryption: NO
[17:27:21][C][sntp:050]: SNTP Time:
[17:27:21][C][sntp:051]:   Server 1: '0.pool.ntp.org'
[17:27:21][C][sntp:052]:   Server 2: '1.pool.ntp.org'
[17:27:21][C][sntp:053]:   Server 3: '2.pool.ntp.org'
[17:27:21][C][sntp:054]:   Timezone: 'UTC0'
[17:27:22][C][mdns:084]: mDNS:
[17:27:22][C][mdns:085]:   Hostname: display_weather
[17:27:22][V][mdns:086]:   Services:
[17:27:22][V][mdns:088]:   - _esphomelib, _tcp, 6053
[17:27:22][V][mdns:090]:     TXT: version = 2022.1.2
[17:27:22][V][mdns:090]:     TXT: mac = 4417931e290d
[17:27:22][V][mdns:090]:     TXT: platform = ESP8266
[17:27:22][V][mdns:090]:     TXT: board = d1_mini
[17:27:22][C][homeassistant.sensor:030]: Homeassistant Sensor 'temperature_office'
[17:27:22][C][homeassistant.sensor:030]:   State Class: ''
[17:27:22][C][homeassistant.sensor:030]:   Unit of Measurement: ''
[17:27:22][C][homeassistant.sensor:030]:   Accuracy Decimals: 1
[17:27:22][C][homeassistant.sensor:031]:   Entity ID: 'sensor.office_temperature_temperature'
[17:27:22][C][homeassistant.text_sensor:023]: Homeassistant Text Sensor 'esp bsched rtn'
[17:27:22][C][homeassistant.text_sensor:024]:   Entity ID: 'sensor.bschet'
[17:27:22][C][homeassistant.text_sensor:023]: Homeassistant Text Sensor 'esp input test rtn'
[17:27:22][C][homeassistant.text_sensor:024]:   Entity ID: 'input_text.text1'
[17:27:30][VV][api.service:337]: on_ping_request: PingRequest {}
[17:27:30][VV][api.service:043]: send_ping_response: PingResponse {}
[17:27:30][D][main:042]: The current bsched is 
[17:27:30][D][main:044]: The current input_text1 is 
[17:27:36][VV][api.service:337]: on_ping_request: PingRequest {}
[17:27:36][VV][api.service:043]: send_ping_response: PingResponse {}
[17:27:45][VV][api.service:337]: on_ping_request: PingRequest {}
[17:27:45][VV][api.service:043]: send_ping_response: PingResponse {}
[17:27:45][D][main:042]: The current bsched is 
[17:27:45][D][main:044]: The current input_text1 is 
[17:27:51][VV][api.service:337]: on_ping_request: PingRequest {}
[17:27:51][VV][api.service:043]: send_ping_response: PingResponse {}
[17:27:53][V][text_sensor:016]: 'esp template test rtn': Received new state Hello World
[17:27:53][D][text_sensor:067]: 'esp template test rtn': Sending state 'Hello World'
[17:27:53][VV][api.service:174]: send_text_sensor_state_response: TextSensorStateResponse {
  key: 1114204214
  state: 'Hello World'
  missing_state: NO
}
[17:28:00][VV][api.service:337]: on_ping_request: PingRequest {}
[17:28:00][VV][api.service:043]: send_ping_response: PingResponse {}
[17:28:00][D][main:042]: The current bsched is 
[17:28:00][D][main:044]: The current input_text1 is 
[17:28:00][V][text_sensor:016]: 'esp bsched rtn': Received new state ESP forced value
[17:28:00][D][text_sensor:067]: 'esp bsched rtn': Sending state 'ESP forced value'
[17:28:00][D][main:071]: The current schedba is ESP forced value
[17:28:00][VV][api.service:174]: send_text_sensor_state_response: TextSensorStateResponse {
  key: 67256600
  state: 'ESP forced value'
  missing_state: NO
}
[17:28:00][D][main:053]: Forcing current input_text1
[17:28:06][VV][api.service:337]: on_ping_request: PingRequest {}
[17:28:06][VV][api.service:043]: send_ping_response: PingResponse {}
[17:28:15][VV][api.service:337]: on_ping_request: PingRequest {}
[17:28:15][VV][api.service:043]: send_ping_response: PingResponse {}
[17:28:15][D][main:042]: The current bsched is ESP forced value
[17:28:15][D][main:044]: The current input_text1 is 
[17:28:21][VV][api.service:337]: on_ping_request: PingRequest {}
[17:28:21][VV][api.service:043]: send_ping_response: PingResponse {}

I think we are at the end of my usefulness on this. I suggest a post on the esphome issues tracker on github.

Ok thank you very much for the support.

Wait, I just looked again at the docs. First thing I notice is

The homeassistant text sensor platform allows you to create a sensors that import states from your Home Assistant instance using the native API

It doesn’t say it is two way!

Also could you change the HA text sensor with a service Native API Component — ESPHome

1 Like

Hi
Thank you very much. :grinning: This is actually a far better approach to achieve what I need as it supports multi dimensional arrays. eg mulit day schedule events with start and stop times. I was raised the issue on the tracker because this should work.

For others who have an issue with text sensors please see the following examples
ESPCode

esphome:
  name: display_weather
  platform: ESP8266
  board: d1_mini
  
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true

api:
  password: !secret api_password
  services:
    - service: update_schedule
      variables:
        my_string: string
      then:
        - globals.set:
            id: my_test_str
            value: !lambda 'return my_string;'

  

ota:
  password: !secret ota_password

logger:
    baud_rate: 0     # Disable UART logging (pins GPIO1/3 are used for Nextion communication)
    # Enable fallback hotspot (captive portal) in case wifi connection fails
    level: VERY_VERBOSE
    logs: 
        api: VERY_VERBOSE
        homeassistant: VERY_VERBOSE
        api.service: VERY_VERBOSE
        sensor: VERY_VERBOSE
        scheduler: DEBUG
        
globals:
 - id: my_test_str            
   type: std::string
   restore_value: no
   initial_value: ''

time:
  - platform: sntp
    id: sntp_time
    on_time:
      # Every 15 seconds
      - seconds: /15
        
        then:
          - lambda: |-

                ESP_LOGD("main", "The current schedule is %s", id(my_test_str).c_str());
                std::string val = id(bsched).state;
                val = id(input_text1).state;
                ESP_LOGD("main", "The current input_text1 is %s", val.c_str());
      
          # Every1 minutes
      - seconds: /30
        minutes: /2
        then:
            - lambda: |-
                  std::string val = id(bsched).state;
                  id(bsched).publish_state("ESP forced value");
                  ESP_LOGD("main", "Forcing current input_text1");

                
sensor:
 
  - platform: homeassistant   # Office temperature
    id: temperature_office
    entity_id: sensor.office_temperature_temperature
    internal: true
    
text_sensor:
  - platform:  homeassistant
    entity_id:  sensor.bschet
    name: "esp bsched rtn"
    id: bsched
    on_value:
      then:
        - lambda: |-
            ESP_LOGD("main", "The current schedba is %s", x.c_str());
            
  - platform: homeassistant
    name: "esp input test rtn"
    entity_id: input_text.text1
    id: input_text1
    on_value:
       then:
         - lambda:  ESP_LOGD("main", "The current input_text1 is %s", x.c_str());

  - platform: template
    name: "esp template test rtn"
    id: bscheda
    lambda: |-
      return {"Hello World"};
    update_interval: 60s       

HA script

script:
  send_schedule_to_boiler:
  service: esphome.display_weather_update_schedule
data:
  my_string: Example qwerty

Cheers

Hi @pebblebed,
I’m facing kind of similar problem (ha issue) trying to implement a kind of two way binding and I’m not totally sure how your solution works. Could you please post a very short example like only the components needed?

Reading the code pasted I guess there’s a service with name update_schedule?! and on value it sets the global variable with name my_test_str with the value of my_string variable of service. So maybe that’s not important for updating value in ha ui, because I also could write id(text_sensor_id).state.

Then there are some cron jobs, first one just logging. Second one publishing values to text sensor ← does this work - for me it doesn’t?

Then there is an sensor temperature_office not needed for example and 3 others from which I’m not sure what their purpose is.

HA script: I dont know what it is for :smiley:

Sry if the question may be dump as I’m not that much into ha and just wanted to give it a try :woman_shrugging:

BR
i7i5

Basically the code was there to a demonstrate the issue with string sensors this has now been raise as a ESPHome issue Issue #2990. The solution / work around was to use a service to send string values from HA to the ESP device.
I would suggest for you to achieve two way binding you would need to two sensors one mapped to a HA virtual entity and a virtual sensor on the ESP device this would then allow data from HA to be sent to the device and then using the appropriate trigger run some lambda code to change the value and report it back to HA. Then at the HA end another trigger to detect changes in the ESP virtual sensor. But a not of warning if you make this close loop you could end up with a deadly embrace eg the sensor updating it self repeatedly

1 Like