How to improve SwitchBot Meter sensor from API

Hello!

I have managed to read from the SwitchbBot API a Meter device, but I don’t know if there is any way to improve it.

image

My sensors.yaml file:

# ---------------------------------------------------------------------
#   SwitchBot
#   API: https://github.com/OpenWonderLabs/SwitchBotAPI
#   https://peyanski.com/home-assistant-switchbot-curtain-integration
# ---------------------------------------------------------------------

- platform: rest
  resource: !secret switchbot_meter_status_url
  method: GET
  name: switchbot_meter
  value_template: 'OK'
  json_attributes:
    - temperature
    - humidity
  json_attributes_path: "$.body"
  headers:
    Authorization: !secret switchbot_api
    Content-Type: "application/json"
  scan_interval: 300
- platform: template
  sensors:
    switchbot_temperatura:
      value_template: "{{ state_attr('sensor.switchbot_meter', 'temperature') }}"
      unit_of_measurement: "ºC"
    switchbot_humedad:
      value_template: "{{ state_attr('sensor.switchbot_meter', 'humidity') }}"
      unit_of_measurement: "%HR"

I have created a rest.yaml file with this configuration and it seems to be more optimized.

# ---------------------------------------------------------------------
#   SwitchBot
#   API: https://github.com/OpenWonderLabs/SwitchBotAPI
#   https://peyanski.com/home-assistant-switchbot-curtain-integration
# ---------------------------------------------------------------------

- resource: !secret switchbot_meter_status_url
  method: GET
  headers:
    Authorization: !secret switchbot_api
    Content-Type: "application/json"
  scan_interval: 300
  sensor:
    - name: "SwitchBot Temperatura"
      value_template: '{{ value_json.body.temperature }}'
      unit_of_measurement: "ºC"
    - name: "SwitchBot Humedad"
      value_template: '{{ value_json.body.humidity }}'
      unit_of_measurement: "%HR"

image

1 Like