Can't read sensor data in automation

Hi,
I configured a DHT22 sensor through my pi zero GPIO and configured it as follows:

  - platform: dht
    name: 'dht_sensor'
    sensor: DHT22
    pin: 4
    monitored_conditions:
      - temperature
      - humidity

Now I’m trying to send the temperature as a response to Telegram /temp command with no success.
I tried many automation configurations (including templated) with no success

this is only one example:

     service: notify.telegram_test
    data:
      message: states.sensor.dht.temprature.state

what am I doing wrong?

Thanks

P.S
what is the tag for inserting code snippet?

```

(backticks)

You need the sensor code enclosed in brackets, so your message line will be

message: '{{states.sensor.dht.temprature.state}}'

Thanks,
I used the brackets with many different parameters that didn’t work.
After more reading I managed to find this post:

with one comment suggesting to remove the “name” field and referring the sensor as:
dht_sensor_temperature (or humidity)

Now it works like a charm.

- alias: 'Telegram get temp inline'
  hide_entity: true
  trigger:
    platform: event
    event_type: telegram_callback
    event_data:
      data: '/temp'
  action:
    service: notify.telegram_test
    data:
      message: '{{  states.sensor.dht_sensor_temperature.state}} °C
2 Likes

Hey all of the above you did, i.e. getting temp in telegram. did you do this in the config file or did you write another script for this?

if you did write a script how to you point the config to go get the script file?