How to get input_datetime to ESPhome

Hello …
i have a helper in HA Named “input_datetime.anzuchtbox_licht_startzeit”
how to get the hour component from this time select frontend as a int or float in my ESPHome

i try something like this and it doesnt work please help
i have no Problems with Arduino Staff but ESPhome kills me

text_sensor:

  - platform: homeassistant

    id: StartZeit2

    entity_id: input_datetime.anzuchtbox_licht_startzeit

    attribute: hour    

interval:

  - interval: 10sec

    then:

    - lambda: |-

       float fzeit = id(Startzeit2).state;

       ESP_LOGI("main", "Value of my sensor: %f", fzeit);

So what does your log look like? What errors do you get?

If you get a value in the text sensor, to convert it to a float:

    - lambda: |-

       float fzeit = atof((id(Startzeit2).state.c_str());

Also your sensor name is case sensitive. Use lower case is usually the ESPHome standard.

Hello …
i dont know if the HA Type input_datetime have to tranfer as Textsensor or number sensor to Esphome
cant find any usefull docs.This is my time frontend


so i tried both without sucsess

i tried your float conversion too, the result in log is 0.000000 the timeset in HA is 08:02

text_sensor:
  - platform: homeassistant
    id: startzeit
    entity_id: input_datetime.anzuchtbox_licht_startzeit
    attribute: hour
    on_value:
      then:
        - lambda: |-
            ESP_LOGD("main", "Starttime set to: %s", x.c_str());

interval:
  - interval: 10sec
    then:
    - lambda: |-
       float fzeit = atof(id(startzeit).state.c_str());
       ESP_LOGI("main", "Value of my sensor: %f", fzeit);

Both of these work - the log output is below. The input_datetime is set to “09:36:35”

text_sensor:
  - platform: homeassistant
    id: starttime
    entity_id: input_datetime.start_time
    attribute: hour
    on_value:
      then:
        lambda: |-
          ESP_LOGD("main", "starttime hour value is: %s", x.c_str());

sensor:
  - platform: homeassistant
    id: starttimenum
    entity_id: input_datetime.start_time
    attribute: hour
    on_value:
      then:
        lambda: |-
          ESP_LOGD("main", "starttime hour value is: %f", x);

Result:

[19:01:56][D][homeassistant.text_sensor:015]: 'input_datetime.start_time::hour': Got attribute state '9'
[19:01:56][D][text_sensor:067]: 'starttime': Sending state '9'
[19:01:56][D][main:061]: starttime hour value is: 9
[19:01:56][D][homeassistant.sensor:022]: 'input_datetime.start_time::hour': Got attribute state 9.00
[19:01:56][D][sensor:127]: 'starttimenum': Sending state 9.00000  with 1 decimals of accuracy
[19:01:56][D][main:070]: starttime hour value is: 9.000000

The interval also works:

interval:
  - interval: 10sec
    then:
    - lambda: |-
       float f = atof(id(starttime).state.c_str());
       ESP_LOGD("main", "Value of my sensor: %f", f);

Result:

[19:17:04][D][main:078]: Value of my sensor: 9.000000
[19:17:14][D][main:078]: Value of my sensor: 9.000000
[19:17:24][D][main:078]: Value of my sensor: 9.000000
[19:17:34][D][main:078]: Value of my sensor: 9.000000

So maybe your problem is on the Home Assistant side. When the text sensor is read from HA you will get a line in the log like:

[19:01:56][D][homeassistant.text_sensor:015]: 'input_datetime.start_time::hour': Got attribute state '9'

What do you get?

Hi … thnx for help so much

it work … your right … i forget the API key in HA configuration