How do I send data from a restful api in a message?

In my configuration.yaml file I am fetching some temperature and humidity data from an api. I am successfully displaying this data on my dashboard.
I want to send the data as a notification but I can’t figure out how to add the variables into a notification message. Any help would be great.

Configuration.yaml

> sensor:
>   - platform: rest
>     name: Room Temperature
>     resource: https://api.thingspeak.com/channels/channel_no/feeds.json?api_key=myapikey&results=2
>     value_template: ' {{ float(value_json["feeds"][0]["field1"]) }}'
>     unit_of_measurement: "°C"

Automation.yaml

  • id: ‘1234’
    alias: Temperature
    description: ‘’
    trigger:
    condition:
    action:
    • service: notify.telegram_bot
      metadata: {}
      data:
      message: Temperature is (variable here)
      mode: single
message: "Temperature is {{ states('sensor.room_temperature') }} °C"

Regarding the formatting of your config. You got it right for the template sensor, so there was no need to start every line with >. However for the auomation you used the quote tool rather than pre-formatted text tool.

Untitled

Many thanks for the solution. It works perfectly.

Julian

1 Like