Approach to creating dynamic HA/Alexa query

We are repeatedly asking Alexa what is the temperature inside and outside so we can figure out the differential (is it colder outside? Warmer? By how much?) so we can can determine if it will soon be time to open or close windows.

I already created an automation that announces when it is time to open/close windows if the outside temperature has been lower/higher than the inside temperature for 30 minutes via VoiceMonkey (see below). But I would like to create the following dialog:

“Alexa, what is the current temperature difference?”
“The outside temperature is warmer than the inside by 17 degrees”.

What would be the approach for implementing this?

Here’s what I’m thinking so far:

  1. Use a custom Alexa command to toggle a virtual SmartHome light
  2. HA automation on virtual light toggling
    a. Query computed “inside and outside temperature difference” sensor
    b. Determine warmer/colder
    c. Send announcement to Alexa via VoiceMonkey.

I know how to do 1, and 2a. I think 2b and 2c will involve some sort of template but my knowledge of templates is rather limited.

Before I start digging further, am I heading in the right direction? If so, any shortcuts or code snippets to offer?

alias: When it gets warmer outside
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.outside
    above: sensor.thermostat_temperature
    for: "00:30:00"
condition:
  - condition: time
    after: "09:00:00"
    before: "23:00:00"
action:
  - service: rest_command.voice_monkey_announce
    data:
      monkey: announce-on-kitchen
      announcement: Time to close windows
  - service: rest_command.voice_monkey_announce
    data:
      monkey: announce-on-office
      announcement: Time to close windows
mode: single

Here is a pretty extensive thread discussing what you want:

The template for your message would be something like:

message: >
  {% set in = states(sensor.YOUR_INSIDE_TEMP) | float(0) %}
  {% set out = states(sensor.YOUR_OUTSIDE_TEMP) | float(0) %}
  {% set diff = (out - in) | abs %}
  The outside temperature is {{ iif(out >= in, "warmer", "cooler")  ) }} than the inside by {{ diff }} degrees”.

Another sensor that I have found useful is to compare the Heat Discomfort Index of outside and inside.

Thank you! That should get me where I want to be.

Following up on this, finally implemented the script that simply says whether it is warmer or colder inside than outside and what are both temperatures…

sequence:
  - if:
      - condition: template
        value_template: "   {{ (states('sensor.th_outside_back_temperature') | float(0)) > (states('sensor.inside_temperature') | float(0)) }}"
    then:
      - service: rest_command.voice_monkey_announce
        data:
          monkey: announce-on-kitchen
          announcement: >-
            The current temperature is colder inside. It is {{
            states("sensor.inside_temperature") }} inside and {{
            states("sensor.th_outside_back_temperature") }} outside
    else:
      - service: rest_command.voice_monkey_announce
        data:
          monkey: announce-on-kitchen
          announcement: >-
            The current temperature is warmer inside. It is {{
            states("sensor.inside_temperature") }} inside and {{
            states("sensor.th_outside_back_temperature") }} outside