#Temp conversion in entities

1 messages · Page 1 of 1 (latest)

zinc hemlock
#

I have an esp device that report C temps to HA and the entities are defined in F.
The alert is {{ state_attr(trigger.entity_id, 'friendly_name') }} - ' is ' {{
trigger.to_state.state }}
It reports the C. Should the triggers be based on F or C

mystic fog
#

If the sensor is properly defined (device_class, unit_of_measurement, state_class), as far as i know HA should handle the conversion to the system unit

If that is not the case, your triggers should be in the unit that the device reports

zinc hemlock
#

That's what I am unsure of. The dallas probe reports C. The entity was created by the HA integration with ESPHome Builder and I assume it is coverting to F.

Maybe the Jinja doesnt get the benefit of the conversions and that's why it is reporting C.

So I am guess that the automation trigger should be in F

Does this sound right? The fridge is in the garage and it is really cold there so it isnt running even if the door is left open. The esp is really crammed in there so testing is a little difficult.

mystic fog
#

States don't lie 😬

zinc hemlock
#

If this helps
from the device 'Temprature Freeze': Got Temperature=-13.1°C
from HA entity the temp is 8.6F

mystic fog
zinc hemlock
#

Any suggestion that is better than calcuations in jinja to get it to express in F

tight estuary
#

Just to clarify, you are getting the automation trigger reporting the temperature in C and then when you look at the entity in home assistant the temperature is in F?

zinc hemlock
#

Yes - this is the expression
{{ state_attr(trigger.entity_id, 'friendly_name') }} - ' is ' {{
trigger.to_state.state }}

Trigger is either fridg temp, freezer temp)

mystic fog
#

Oh, ok, i misunderstood then. And i am confused 🤔

zinc hemlock
#

I can add the whole automation to pastebin in that helps. Or recap it here

tight estuary
#

What happens if you change the mode of the automation to parallel from single, does it run twice, once in C, another in F?

zinc hemlock
#

I've not tried that - Didn't know it was even a thing. I'll adjust a few things and try it

tight estuary
#

I think what might be happening is that ESP Home is setting the entity to be in C, your automation is running, HA notices the unit of measurement is C rather than F, and then updates the entity again with the unit conversion, but because the default automation mode is single you don't see that second one

#

If that is the case, you might be able to get around it by putting a condition on it to check the unit_of_measurement attribute is °F

#

so it would ignore that C trigger and work on the F one

zinc hemlock
#

I will play with it some more. I started this months ago and just coming back to it today. It's sorta a stretch for me already. I think my basic question is can I convert in jinja from C to F without math.

#

I think the automation works fine in F and the jinja spits out C.

Does that seem right to you or not?

tight estuary
#

no you have to do maths to do that

#

and no

#

jinja just knows what the number is, it doesn't even know what units are, let alone how to convert them - all of that is done by home assistant

#

and if it's coming in as F it wouldn't convert to C to output it, in fact I don't think it even could...

zinc hemlock
#

The temp def coming in as C. I can see it in the logger.
The entity is set to F by default -- It was created by the integration ha-esphome
I can change the entity to declate C by just changing it

What I am seeing though is the jinja is just spitting out whatever I sent from the esp code

What I would like to is to add a F somewhere in the jinja to get the value comverted

#

When I change the entity it converts the diplayed

#

sorry it converts what HA displays - not what jinja expression shows

tight estuary
#

That's very strange - when I try that with a sensor (defining a template sensor in F) it automatically converts it to C properly

#

can you double check the sensor in either the template editor or states explorer under developer tools?

zinc hemlock
#

the developer shows 9.3F
the logger from the esp device reports -12.7c
it'll take a minute but I'll figure out the template editor ---- great suggestion

tight estuary
#

it might be you need to change your template to {{ states(trigger.entity_id) }} rather than {{ trigger.to_state.state }} - but i can't reproduce the issue with my little toy automation

alias: Test F automation
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.test_f
conditions: []
actions:
  - action: persistent_notification.create
    metadata: {}
    data:
      message: "{{ trigger.to_state.state }}"
mode: single
#

and that's with the "temperature sensor" being a template sensor mirroring an input_number and pretending to be a temperature in F - i only get the state being reported as a temperature in C, which annoyingly kinda invalidates my earlier theory

daring fiber
#

I have an ESPHome device that is configured to report degC, and my HA instance converts it to degF since I have US customary units as my preferences. And when used in an automation, trigger.to_state.state reports the converted degF value. Because that is the sensor's state.

zinc hemlock
#

I'll look at that too.

I'm really outta my depth here so will go work on both of these things for a bit

I've broken the automation as well so have three balls juggling

I sincerely appreciate the help. I need to struggle a bit with this so that I will hopefully remember. I recall a long bit ago having another issue with a device I put together and the conversion. This last suggestion is what triggered that memory so..... Maybe
I wish I was faster at this but do need to consider my capacity.

I'll try to come back with an ansewr

tight estuary
#

no worries

mystic fog
#

So you say the temp sensor is ESPHome. Can we see the config for it?

zinc hemlock
#

#dallas:
one_wire:

  • platform: gpio
    pin: D2

Individual sensors

sensor:

  • platform: dallas_temp
    address: 0x883ce1e380482828
    name: "Temperature Fridg"
    id: temp_sensor0
  • platform: dallas_temp
    address: 0x963ce1e38013b528
    name: "Temprature Freeze"
    id: temp_sensor1
flint finchBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

zinc hemlock
#

lol - just notices the spelling

#

'''
#dallas:
one_wire:

  • platform: gpio
    pin: D2

Individual sensors

sensor:

  • platform: dallas_temp
    address: 0x883ce1e380482828
    name: "Temperature Fridg"
    id: temp_sensor0
  • platform: dallas_temp
    address: 0x963ce1e38013b528
    name: "Temprature Freeze"
    id: temp_sensor1
flint finchBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

mystic fog
#

Please?

zinc hemlock
#

the whole thing?

daring fiber
#

backticks are different from single quotes

#

if you have a US keyboard, it's the button that also has a tilde

mystic fog
zinc hemlock
#
#dallas:
one_wire:
  - platform: gpio
    pin: D2
# Individual sensors
sensor:
  - platform: dallas_temp
    address: 0x883ce1e380482828
    name: "Temperature Fridg"
    id: temp_sensor0
  - platform: dallas_temp  
    address: 0x963ce1e38013b528
    name: "Temprature Freeze"
    id: temp_sensor1
mystic fog
#
#dallas:
one_wire:
  - platform: gpio
    pin: D2
# Individual sensors
sensor:
  - platform: dallas_temp
    address: 0x883ce1e380482828
    name: "Temperature Fridg"
    id: temp_sensor0
    unit_of_measurement: "°C"
    device_class: "temperature"
    state_class: "measurement"
  - platform: dallas_temp  
    address: 0x963ce1e38013b528
    name: "Temprature Freeze"
    id: temp_sensor1
    unit_of_measurement: "°C"
    device_class: "temperature"
    state_class: "measurement"
#

Update the config, flash the new one and the sensors should be properly defined in HA, conversion should take place automatically and your trigger in F should work, as mekaneck and i suggested

zinc hemlock
#
'Garage Freezer Temp: uptime': Sending state 164457.28125 s with 0 decimals of accuracy
13:04:10    [D]    [sensor:093]    
'Garage Freezer Temp: WiFi Signal': Sending state -76.00000 dBm with 0 decimals of accuracy
13:04:15    [D]    [dallas.temp.sensor:054]    
'Temperature Fridg': Got Temperature=-3.2°C
13:04:15    [D]    [sensor:093]    
'Temperature Fridg': Sending state -3.25000 °C with 1 decimals of accuracy
13:04:21    [D]    [sensor:093]    
'garagefreezertemp WiFi Signal': Sending state -76.00000 dBm with 0 decimals of accuracy
13:04:24    [D]    [dallas.temp.sensor:054]    
'Temprature Freeze': Got Temperature=-12.4°C
13:04:24    [D]    [sensor:093]    
'Temprature Freeze': Sending state -12.37500 °C with 1 decimals of accuracy
13:04:31    [D]    [sensor:093]    
'Garage Freezer Temp: uptime': Sending state 164517.28125 s with 0 decimals of accuracy
13:05:10    [D]    [sensor:093]    
'Garage Freezer Temp: WiFi Signal': Sending state -76.00000 dBm with 0 decimals of accuracy
13:05:15    [D]    [dallas.temp.sensor:054]    
'Temperature Fridg': Got Temperature=-3.2°C

It seems that C is the default but I can add the those statements too

I super happy with all the help but need to tune out to try these points. I'll answer back but need to go try some of this. I am a bit overwhelmed. My image on discord is many years ago. My brain plasticity isnt what it used to be. Thank you

mystic fog
#

Hmm, apparently those attributes should have been added as defaults to the ESPHome config 🤔 so they are not really necessary as explicit config options

daring fiber
#

I'm looking this thread over. It would be helpful if you would do the following:

  1. In HA, go to developer tools -> states, find the "Temprature Freeze" entity, and share its state and attributes. (you can take a screenshot)
  2. In HA, go to developer tools -> template, delete everything in the editor, and then type {{ states('sensor.temprature_freeze') }} and share the output of that template. If that isn't the correct entity_id, change it to whatever the right entity is.
zinc hemlock
#

In the end - I think I had a some things confused (and my state as well). The ESP device sends C degrees in this case. HA entities are showing F for my user. I assume that is based on my user settings. Developer States tool and the template support this.
I am able to change the entities to show C (or even K). This made me curious and it seems the automation tool does not take the UOM into account. Not surprising given it's role.

The ridiculously cold temperature in our garage has led to some surprising frozen stuff in both refrigerator and freezer. I think I ended up with a good solution but have on last question. The esp sends the values every 60 seconds and I would like to test the automation. Can I use the States tool to change the temperature and test the alerts monitor?

Thanks for your help today, you are appreciated