Help with Graphing the difference between 2 sensors in Lovelace

I’ve successfully defined 2 sensors and got a graph with these 2 temp sensors on it but what I really want is to graph only the absolute value of the difference between the sensors ie sensor1-sensor2 over a week.

  - platform: template
    sensors:
      temperature_loc1:
        friendly_name: "Temp1"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('weather.loc1', 'temperature') }}"

What’s the best way to do that? I’d also like to create a history graph of the same thing, over a month.

Would this be another sensor template? I tried this with no luck…

  - platform: template
    sensors:
      temperature_diff:
        friendly_name: "Temperature difference"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('weather.loc1', 'temperature') 
 - state_attr('weather.loc2', 'temperature') }}"

Thanks for any advice!

Jeff

try something like this

“{{ state_attr(‘weather.loc1’, ‘temperature’)|int - state_attr(‘weather.loc2’, ‘temperature’)|int }}”

I get this in the template tool

Error rendering template: TemplateSyntaxError: unexpected char ‘‘’ at 14

EDIT: fixed that but the calc gives me 0 and I know it’s 12

can you write what are exact values of that attributes? Are there any Celsius signs or something else?

Got it. States, not attribute!

{{ states("sensor.loc1_temperature")|int  -  states("sensor.loc2_temperature")|int }}

Thanks for the push!