Sonoff TH16, how to use it?

Hello,

i am using Home Assistant 2021.1.5 on a raspberyy pi 4 4gb.
My knowledge is practically 0 in this area. I did manage to connect my Ewelink (Sonoff account) to home assistant, with the Hacs integration + sonoff lan.
All the devices show up correctly, but the TH16 device is not recognised as a sensor but as a switch.

it shows a bunch of information on the right side of entity list:

manufacturer: SONOFF
model: TH16
sw_version: PSA-BHA-GL v3.4.1
local: online
cloud: online
rssi: -56
humidity: 42
temperature: 21.6
friendly_name: Thermometer
supported_features: 0

Iā€™ve looked at templates for generic sensors but i really dont know what im doing.
Is there a way to extract the humidty and temperature from this device and show it in a Card?

thank you for your time

Hi thereā€¦welcome. there are two methods to achieve what you have asked for. The simplest method would be to create two template sensors from this and use then in the dashboard. In this method you can create template sensors by adding the following to config.

sensor:
  - platform: template
    sensors:
      sonoff_temperature:
        friendly_name: "Temperature"
        unit_of_measurement: 'Ā°C'
        value_template: "{{ state_attr('<entity_id>', 'temperature') }}"
      sonoff_humidity:
        friendly_name: "Humidity"
        unit_of_measurement: '%'
        value_template: "{{ state_attr('<entity_id>', 'humidity') }}"

You can edit the name and other details of this configuration but dont forget to add the entity_id of this switch in the place I have mentioned <entity_id>. The entity id would be something like switch.<something>

After this you will have to restart your HA server and then you would see two new sensors with temperature and humidy. you can use this in dashboard.

2 Likes

Hi Sheminasalam,

Thank you so much for your help, i have added this code to the configuation file and replaced the <entity_id> with the sonof id. After the reboot it does show me the 2 icons for temperature and humidity, but it says unknown on the right side.

It says ā€œt This entity (ā€œsensor.sonoff_temperatureā€) does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.ā€

what is the state of sensor.sonoff_temperature? Also please share the entity_id of the sonoff switch.

The state of sensor.sonoff_temperature says ā€œunknownā€
The sonoff switch id is : switch.sonoff_1000beb186

Just check if this is the config.

sensor:
  - platform: template
    sensors:
      sonoff_temperature:
        friendly_name: "Temperature"
        unit_of_measurement: 'Ā°C'
        value_template: "{{ state_attr('switch.sonoff_1000beb186', 'temperature') }}"
      sonoff_humidity:
        friendly_name: "Humidity"
        unit_of_measurement: '%'
        value_template: "{{ state_attr('switch.sonoff_1000beb186', 'humidity') }}"
2 Likes

i copied your code and put it in the config, then restarted the server.

now it is showing up perfectly!

Thank you so much for your time and effort

1 Like

sheminasalam :clap: :+1: :clap: :+1: thanks ,the code works perfectly

1 Like

Hello to all, and first of all, I want to say Thank you to all people that are helping us (newbies) here.
I have installed same sonoff TH16 sensor, with the help of this forum users I managed to display data from it, but is there a way to force refresh it? Sometimes it gives me data from few mins ago, sometimes it returns data from hours ago, and ā€¦ I donā€™t know how to force refresh on a fixed interval of time, or on demand. Thank you in advance.

Hello Laurentiu,

i opened another topic facing the exact same question:

Long story sort, you cant do it without flashing other software on it.

If you use the AlexxIT / SonoffLAN integration you can configure the refresh interval by setting i.e.

scan_interval: '00:05:00' # (optional) default 5 minutes

within the sonoff-block inside configuration.yaml.

Can you please give me an example of configuration for this scan_interval ?
And where exactly to add it? Iā€™m new to HA and donā€™t know yet what files are for configuration.
This is my configuration, but ā€¦ it does not update :
sonoff:
username: xxxxx
password: xxxxx
reload: always
scan_interval: ā€˜00:01:00ā€™
devices:
10010b8405:
name: Sonoff TH
force_update: True

sensor:

  • platform: template
    sensors:
    sonoff_temperature:
    friendly_name: ā€œTemperatureā€
    unit_of_measurement: ā€˜Ā°Cā€™
    value_template: ā€œ{{ state_attr(ā€˜switch.sonoff_10010b8405ā€™, ā€˜temperatureā€™) }}ā€
    sonoff_humidity:
    friendly_name: ā€œHumidityā€
    unit_of_measurement: ā€˜%ā€™
    value_template: ā€œ{{ state_attr(ā€˜switch.sonoff_10010b8405ā€™, ā€˜humidityā€™) }}ā€

As I mentioned it before the scan_interval-directive only applies if you use the AlexxIT / SonoffLAN custom integration (which I recommend since you will be able to circumvent the eWeLink/Sonoff-Cloud but run your THā€™s etc. locally).

If you use that custom integration the sonoff-block inside configuration.yaml looks like i.e.:

  sonoff:
    username: !secret sonoff_usr
    password: !secret sonoff_pwd
    force_update: [temperature, power]
    scan_interval: '00:05:00'  # (optional) default 5 minutes
    sensors: [temperature, humidity, power]
    mode: local
    reload: always  # update device list every time HA starts

Thank you, but I donā€™t have all necessary hardware for flashing it.

Tamsy, maybe Iā€™m to stupid to understand. Now I have the following configuration in configuration.yaml

sonoff:
username: xxx
password: xxx
force_update: [temperature, humidity, power]
scan_interval: ā€˜00:01:00ā€™
sensors: [temperature, humidity, power, current, voltage]
mode: cloud
reload: always

I tried to set interval to 1 min just to see if it is updating, I tried with mode : local and cloud, but still not updating, when I check updating time, always shows more than 1 min.
What Iā€™m doing wrong? Iā€™m using AlexxIT/ SonoffLAN

So, without flashing, but using AlexxIT/ SonoffLAN we cant force scan_interval every X minutes, is that right?

That is correct:
scan_interval: '00:05:00' # (optional) default 5 minutes

Thanks for the reply @Tamsy!

We put scan_interval: '00:05:00' # (optional) default 5 minutes at configuration.yaml file below ewelink account credentials, right> If yes, i have already tested with out any resultsā€¦

I donā€™t use the ewelink integration here, purely AlexxIT/ SonoffLAN installed through HACS.

Inside configuration.yaml, sonoff-part (for TH10 & TH16):

  sonoff:
    username: !secret sonoff_usr
    password: !secret sonoff_pwd
    mode: local
    reload: always # update device list every time HA starts
    force_update: [temperature, power]
    scan_interval: '00:00:30' # (optional) default 5 minutes
    sensors: [temperature, humidity, power, current, voltage]

OK, Nice, thanks for the reply.

Here is the issue: When i add the mode: local i dont see temperatures. If i comment it, temps appeared.

Why is that?

Can you check my config and tell me whats wrong?

Might at ā€œsensorsā€ i must put my sensor names?

sonoff:
  username: [email protected]
  password: ****
  mode: local
  reload: always # update device list every time HA starts
  force_update: [temperature, power]
  scan_interval: '00:00:30' # (optional) default 5 minutes
  sensors: [temperature, humidity, power, current, voltage]

  # Example configuration.yaml entry
sensor:
  - platform: template
    sensors:

      water_temperature:
        friendly_name: 'Water Heater'
        unit_of_measurement: 'Ā°C'
        value_template: "{{ state_attr('switch.sonoff_1001200fb3', 'temperature') }}"

      kitchen_radiator:
        friendly_name: 'Kitchen Temperature'
        unit_of_measurement: 'Ā°C'
        value_template: "{{ state_attr('switch.sonoff_100114ad27', 'temperature') }}"

      kitchen_humidity:
        friendly_name: 'Kitchen Humidity'
        unit_of_measurement: '%'
        value_template: "{{ state_attr('switch.sonoff_100114ad27', 'humidity') }}"

      dining_room_radiator:
        friendly_name: 'Dining Room Temperature'
        unit_of_measurement: 'Ā°C'
        value_template: "{{ state_attr('switch.sonoff_100114ad74', 'temperature') }}"

      dining_room_humidity:
        friendly_name: 'Dining Room Humidity'
        unit_of_measurement: '%'
        value_template: "{{ state_attr('switch.sonoff_100114ad74', 'humidity') }}"

      living_room_radiator:
        friendly_name: 'Living Room Temperature'
        unit_of_measurement: 'Ā°C'
        value_template: "{{ state_attr('switch.sonoff_100114adcf', 'temperature') }}"

      living_room_humidity:
        friendly_name: 'Living Room Humidity'
        unit_of_measurement: '%'
        value_template: "{{ state_attr('switch.sonoff_100114adcf', 'humidity') }}"

      basement_temperature:
        friendly_name: 'Basement Temperature'
        unit_of_measurement: 'Ā°C'
        value_template: "{{ state_attr('switch.sonoff_1000fde8f8', 'temperature') }}"

      basement_humidity:
        friendly_name: 'Basement Humidity'
        unit_of_measurement: '%'
        value_template: "{{ state_attr('switch.sonoff_1000fde8f8', 'humidity') }}"

Have you restarted HA after you made changes to configuration.yaml?

Also go to

Home Assistant --> Developer Tools and look for switch.sonoff_100114ad74. What is listed below ā€œAttributesā€ for your switch?