Create one temperature sensor using the data of two temperature sensors

Hi there,

Any help on how to handle a little problem with my adjusted Osram Smart+ motion sensor temperature. Because this adjustment it means now and then (at restart for example) the adjusted temperature sensor show only this adjusted part:

image

It means some problems:

  • It ruins the statistics
  • It is also problematic in heating solutions - it sets the heating on when thinking it is only 0,7 C in the room. For a while but still.

Because I use these in heating I have some backup sensors just in case I can handle the problems remotely. I feel these Osrams follow the temperature better than for instance Xiaomis. Solution could be to create a sensor which uses xiaomi value when adjusted Osram shows only a adjustment part? But how?

Once again here from the backseat as a “Passenger” I trust on you great “Drivers”

Any suggestions here?

if this is temperature inside your home it’ll never go below 5ÂșC one would hope, so you could instead use a template sensor and set it to the Osram value only if the temp is above 5
Let me know if you need help

Thanks for a very quick response!

I actually use platform template to calibrate (adjust) the the value from Osram. And to be honest sometimes the temperature of that place inside might drop to - 25 C. It’s is my summer cabin which might be quite cold winter time without heating. And that’s what I control with this sensor. I also have some other applications where I need to solve this problem when adjusted temperature drops to adjustment value in certain situations.

  - platform: template
    sensors:
      osram_olkkari_temppi:
        friendly_name: "OsramOlkkariTemp"
        unit_of_measurement: '°C'
        value_template: >-
          {{ '%0.1f'|format(states('sensor.olohuone_osram_temp')|float + 1) }}

Try this:

  - platform: template
    sensors:
      osram_olkkari_temppi:
        friendly_name: "OsramOlkkariTemp"
        unit_of_measurement: '°C'
        value_template: >
          {{ '%0.1f'|format(states('sensor.olohuone_osram_temp')|float + 1) }}
        availability_template: >
          {{ states('sensor.olohuone_osram_temp') not in ['unknown', 'unavailable', 'none'] }}
1 Like

Have you tried a value template like
{% if states('sensor.olohuone_osram_temp')|float <= 0 %}{{ states('sensor.osram_olkkari_temppi') }} {% else %}{{ states('sensor.osram_olkkari_temppi')|float + 1 }} {% endif %}
The other way would be to check the season and / or outside temperature to set your check
When do you get that issue with the drop?
If it’s just at restart, you could set a check that there has been at least 30 sec since restart
I use the uptime sensor with unit_of_measurement: hours and this condition in an automation:
(states("sensor.uptime") | float > 0.1)

Thanks!

As mentioned before being as a passenger not a driver, I do not exactly understand what that does. I guess it means template does not provide the adjusted value if Osram is not ready to provide its value? I suppose this situation is due to the fact that Deconz addon is not ready yet to provide the sensor data to homeassistant after the restart?

Based on your answer, is there a possibility to create a sensor which will use other sensor value if primary is not available?

To be honest once again I do not have competence to comment your detailed proposals. However I think my problem is not related to environment temperature.

This issue will also happen when Osram for some reason drops from Deconz mesh.

I think the best solution is: if Osram is not available use the secondary sensor value. But I do not know how to write that code in template.

try this:

{% if states('sensor.olohuone_osram_temp') not in ['unknown', 'unavailable', 'none'] %}{{ states('sensor.olohuone_osram_temp') | float + 1  }} {% else %}{{ states('sensor.osram_olkkari_temppi')}} {% endif %}

You may need to list the entities to monitor so HA knows when to update your template sensor
The full declaration would be

 - platform: template
    sensors:
      osram_olkkari_temppi:
        friendly_name: "OsramOlkkariTemp"
        unit_of_measurement: '°C'
        entity_id: sensor.olohuone_osram_temp
        value_template: >
          {% if states('sensor.olohuone_osram_temp') not in ['unknown', 'unavailable', 'none'] %}
          {{ states('sensor.olohuone_osram_temp') | float + 1  }}
          {% else %}
          {{ states('sensor.osram_olkkari_temppi')}}
          {% endif %}

what’s the point of multiline templates if you don’t post it in an easy to read fashion?

Thanks, edited and fixed typo as well. Guess I should stop multi-tasking :wink:

1 Like

To be honest as a “passenger” I do not understand what is your code using as the value when “sensor.olohuone_osram_temp” is not available.

I have a secondary sensor called: sensor.olohuone_temp which value I would like to use if sensor.olohuone_osram_temp is not available?

then change that entity to sensor.olohuone_osram_temp


Do you understand/know what if statements are?

Ok, I think I understand.

The reason why I am confused is because I understand we are creating actually this sensor.osram_olkkari_temppi (so how can it be an alternative if we just can not know its value. But to replace that with secondary sensor entity makes sense.

{{ states(‘sensor.olohuone_temp’)}}

Not sensor.olohuone_osram_temp (that’s the primary sensor) Right?

You can have a sensor reference itself. It will pull the last piece of information that it had. All @lolouk44 is doing is saying that “if we have valid data, use it, otherwise use our previous data”.

1 Like

Ok - as a passeger I edited provided solution a bit and this is what I tested and it worked. Sorry for the different sensors but they were easier to test:

      osram_vierashuone_temppi:
        friendly_name: "OsramVierashuoneTemppi"
        unit_of_measurement: '°C'
        value_template: >
          {% if states('sensor.vierashuone_osram_temp') not in ['unknown', 'unavailable', 'none'] %}
          {{ '%0.1f'|format(states('sensor.vierashuone_osram_temp')|float + 2.7) }}
          {% else %}
          {{ states('sensor.vierashuone_temp')}}
          {% endif %}

Does it look OK for you Drivers?

And of course many thanks for helping me out with this issue - once again!