Sensor Help

This is my first attempt at a custom sensor and I could use a little help.

The Traeger integration creates a climate entity that tracks the meat probe. The setpoint is the target temperature of the meat and then there is the current temp. I’d like to create a sensor the percentage done. For example if the meats at 80 and the setpoint is 120 then the sensor would be 80/120 = 66%. Seems like it should be doable but I am lost.

What are the entity ids that hold your two temperatures?

I think they are different attributes of the same entity? climate.traeger_probe_p0

image

Can you copy the attributes of the entity from the Developer tools > States menu and paste them here?

Don’t post a screenshot of the text.

Like this?

hvac_modes: heat, off
min_temp: 115
max_temp: 215
target_temp_step: 5
current_temperature: 101
temperature: 120
attribution:
integration: traeger
icon: mdi:thermometer
friendly_name: Traeger Probe p0
supported_features: 1

Yes like that.

Try this:

template:
  - sensor:
      - name: "Percent Done"
        icon: "mdi:food-steak"
        unit_of_measurement: "%"
        state: "{{ ( 100 * state_attr('climate.traeger_probe_p0', 'current_temperature')|float(0) / state_attr('climate.traeger_probe_p0', 'temperature')|float(1) )|round(0) }}"
        availability: "{{ state_attr('climate.traeger_probe_p0', 'current_temperature')|is_number and state_attr('climate.traeger_probe_p0', 'temperature')|is_number }}"
1 Like

Should I put this in configuration.yaml or sensors.yaml?

That one would work in configuration.yaml (or a package if you get to that point in the future)

Got this error.

Invalid config for [template]: invalid template (TemplateSyntaxError: expected token ')', got 'float') for dictionary value @ data['sensor'][0]['state']. Got "{{ ( 100 * state_attr('climate.traeger_probe_p0', 'current_temperature')float(0) / state_attr('climate.traeger_probe_p0', 'temperature')float(1) )|round(0) }}". (See /config/configuration.yaml, line 218).
state: "{{ ( 100 * state_attr('climate.traeger_probe_p0', 'current_temperature')|float(0) / state_attr('climate.traeger_probe_p0', 'temperature')|float(1) )|round(0) }}"

That worked, thanks. I’ll test it this weekend.