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

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