Custom Temp Sensor

Hi all,
I did a bit of trawling and could not find answer but apologies if I missed something that should have been obvious.

I have an old raspberry pi 2 that I have connected to 12 or so temp sensors using 1-wire. At moment I have written a python script that polls every minute and updates dummy devices in domoticz with the values.
I am trying to replicate this in HASS with mixed results. This is what I have tried -

sensor:
  - platform: template
    sensors:
      playroom:
        friendly_name: "Playroom"
        unit_of_measurement: '°C'
        icon_template: "mdi:thermometer"
        value_template:  "{{ state_attr('value') }}"
      hall:
        friendly_name: "Hall"
        unit_of_measurement: '°C'
        icon_template: "mdi:thermometer"
        value_template:  "{{ state_attr('value') }}"
      back_bedroom:
        friendly_name: "Back bedroom"
        unit_of_measurement: '°C'
        icon_template: "mdi:thermometer"
        value_template:  "{{ state_attr('value') }}"
      sun_room:
        friendly_name: "Sun Room"
        unit_of_measurement: '°C'
        icon_template: "mdi:thermometer"
        value_template:  "{{ state_attr('value') }}"
[..]

I then use a python script to send the values to HAAS as I did for domoticz. I end up with :

Is this how it should look? Also can I assign entity_ids to them? Is there a way to show the “C” or some other way to make apparent it is a temp? And is there a way to color code based on temp ranges?

Thanks!

In this example, the entity_id is sensor.playroom,

sensors:
  playroom:
    friendly_name: "Playroom"
    unit_of_measurement: '°C'
    icon_template: "mdi:thermometer"
    value_template:  "{{ state_attr('value') }}"

And yes, this is how it is supposed to look like, add
device_class: temperature
to each sensor and then you should get a red circle with °C at the bottom of the circle like for the SonoffOu..status

Thank you! I will try that. I had assumed that that was the entity Id as I had to use it for sending the data to HAAS api. But the GUI complains that there is no entity ID which was confusing.

PS. I also get TypeError: state_attr() missing 1 required positional argument: 'name'for each dev in the log.

I reread you post and you don’t need a value_template here at all. In fact, you don’t even need to define the sensor in Home Assistant, you can send all the relevant information including unit_of_measurement etc. through the REST API from the python script. However, the sensors will disappear when Home Assistant restarts until the next measurement is received.
If you can, I’d publish the data from the python script to an MQTT topic and integrate it to Home Assistant with MQTT.

Thanks :slight_smile:
That was where I was heading towards. Appreciate the help.