Help configuring yaml customizing sensor to get temp and moisture readings in graph instead of color bar

Hi everyone,

I hope someone can help me with what seems to be a small configuration problem.
I’ve searched and tried a number of things, but am unable to find and apply the info I need. I am a beginner.

I’ve bought a dragino LORA soil moisture and temperature sensor which communicates with TTN. IN HA the “The Things Network” integration receives data and HA automatically created sensor entities:

When using the entities in a dashboard I get the color bar instead of a graph.
Same as in this post, which I read when trying to fix it.

I then tried:

But this does not work as there is no place to enter either device_class or unit_of_measurement.

I think I need to edit either the configuration.yaml and/or the sensors.yaml and/or a template.yaml (although I understood from somewhere sensors.yaml might be reserved for binary sensors?)
but I am unable to find a working configuration with the right indentation.
My current config in configuration.yaml is:

# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
#sensor: !include sensors.yaml
template: !include templates.yaml
sensor:
  - name: "Compost 1 Temp Sensor"
    platform: thethingsnetwork
    unit_of_measurement: °C
    state: "{{ states('sensor.se01_lb_001_temp_soil') }}"
    device_class: "temperature"
    state_class: "measurement" 
  - name: "Compost 1 Moisture Sensor"
    platform: thethingsnetwork
    state: "{{ states('sensor.se01_lb_001_water_soil') }}"
    device_class: "moisture"
    state_class: "measurement"

I still can’t select the entities/sensors anywhere and also can’t see the data as graph in either dashboard or statistic graph.

I hope someone can help me out.
Best regards,
Okat

sensor:
  - name: "Compost 1 Temp Sensor"
    platform: thethingsnetwork
    unit_of_measurement: °C
    state: "{{ states('sensor.se01_lb_001_temp_soil') }}"
    device_class: "temperature"
    state_class: "measurement" 
  - name: "Compost 1 Moisture Sensor"
    platform: thethingsnetwork
    state: "{{ states('sensor.se01_lb_001_water_soil') }}"
    device_class: "moisture"
    state_class: "measurement"

That part doesn’t look right. It looks like a mashup of legacy and current template sensor syntaxes with a dash of make believe… Is it AI generated?

Based on what you have described, there is no need for new sensor entities, just add the attributes via customize:

# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
#sensor: !include sensors.yaml
template: !include templates.yaml

homeassistant:
  customize:
    sensor.se01_lb_001_temp_soil:
      device_class: "temperature"
      state_class: "measurement"
      unit_of_measurement: °C
    sensor.se01_lb_001_water_soil:
      unit_of_measurement: "%"
      device_class: "moisture"
      state_class: "measurement"

Hi there,

Thanks for taking the time to answer me! Much appreciated.

I guess that’s what one gets when mucking about with old answers to more or less similar problems :slight_smile: It was all me… I got lost.

Would sensors.yaml be the best place to move the code? Or is that file reserved for binary sensors (read that somewhere I think)

I got it working perfectly by copy/pasting your code. But after I tried adding code
for the battery in the same device I got an indentation error which I couldn’t fix. Now when I empty the file and copy/paste only your code it keeps throwing this error:

bad indentation of a mapping entry (20:28)

 17 |       state_class: "measurement"
 18 |       unit_of_measurement: °C
 19 |     sensor.se01_lb_001_water_soil:
 20 |       unit_of_measurement: %
---------------------------------^
 21 |       device_class: "moisture"
 22 |       state_class: "measurement"

When I remove the percentage sign the above file editor warning is gone and returns when I put it back. I’m so confused. I read somewhere the unit_of_measurement of moisture is percentage by default. Any Idea if that’s true?

config check throws:

What code are you talking about? If you are asking about the block I quoted… unless you have information that shows otherwise, I don’t believe it’s valid anywhere. There are no examples of anything like that in the documentation for the “The Things Network” integration.

What are you actually trying to achieve with the new sensor entities that won’t be achieved by using customize?

% should be the default unit of measurement… two options you can try:

  • Remove that entire line
  • Leave the line, but add quotes around %

That seems to have done the trick. Thanks for your effort.

No not my work of art (clears throat). I meant the block you posted. Is configuration.yaml the proper location for it?

Yes, what I posted was what you had posted as “My current config in configuration.yaml”, minus the invalid sensor configuration, and with the manual entity customization added.

:+1: I’ll leave it where it is then.