#Help with Temperature Automation

1 messages · Page 1 of 1 (latest)

torpid fossil
#

Would someone please be able to tell me what I'm doing wrong here? I'm losing my mind and have been at this for hours. Ever since the state_attr stuff was deprecated, none of my temperature-based automations have worked and I'm trying to make sensors that I can use from the get_forecasts service.

#

I just want to get the temperature value of today's high temp

#

I'd do this in the visual editor, as I despise writing YAML, but apparently there is no way to create sensors in automations yet......for some reason

solid lark
#

Hi @torpid fossil,
First it's really hard to help when the code is in picures like that.
I think that alias: tag is out of place, not connected to anything, but I can't tell much else.

torpid fossil
spark sealBOT
#

@torpid fossil 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.

solid lark
#

So are you trying to make an automation, ?

#

I don't know what that is

torpid fossil
#

Yes. I previously used to use "{{ state_attr('weather.home', 'forecast')[0].temperature }}" to pull weather data into an automation, but since that's been removed, annoyingly, I'm trying to make a custom sensor that I can use to compare values in my automations.

solid lark
#

Sensors: doesn't go in an automation, for starters.

#

You might want a template sensor, which is something completely different.

torpid fossil
#

All I want is the high and low temperatures from today's forecast so I can use them in automations.

#

I've been banging my head against the docs off and on for months trying to figure this out

#

This should not be this hard.......

#

and the Template Sensor docs only show you how to do it by YAML, not by using the GUI, so I have no idea what to even enter for the Template data field

#

Based on the docs, it seemed like the ability to create sensors within an automation was added

solid lark
#

Well that's not something I have done, but drop this in a search engine and I can see a bunch of people have in the forums.

site:community.home-assistant.io weather get temperature

torpid fossil
#

..............

solid lark
#

That's BC it a yaml only thing.

torpid fossil
#

Then why is there a GUI option to add a Template Sensor?

solid lark
#

Something new I haven't needed to use, so I don't know.

#

I can only help with what I know about. Someone else will probably drop in and write some code for you, let it cook here a bit,

torpid fossil
#

Appreciate it

obsidian bramble
torpid fossil
#

Yeah I already saw that post. There is someone in there explaining about how weather.get_forecast service is how you're supposed to do it, but the docs don't explain how to do it and neither does the person that on that post, so.......

#

Well I added my stuff to a template.yaml and added it as an include in the configuration.yaml

#

Now I'm getting data for temperature, but it's the current temp.....not the forecasted temp

#

and templow is without value

obsidian bramble
#

If you're using Openweather, they hve a new api 3.0 that requires a CC to be attched, wonder if that provides that information(just guessing, no idea if thats the truth) you get 1000 API calls a day free

torpid fossil
#

I'm not using OpenWeather. I'm using the built in Weather from Met.no

#

weather.forecast_home:
forecast:
- condition: sunny
datetime: "2024-11-18T18:00:00+00:00"
wind_bearing: 275.4
uv_index: 3.8
temperature: 81
templow: 62
wind_speed: 13.42
precipitation: 0
humidity: 19

#

The annoying thing is that the data is RIGHT THERE

torpid fossil
#

Christ this is why I hate YAML......what the hell does that even mean?

torpid fossil
#

OMG I finally got it. In case anyone else suffers like me at this:

#
trigger:
  - platform: time_pattern
    hours: /4
  - platform: homeassistant
    event: start

action: 
  - service: weather.get_forecasts
    target:
      entity_id: weather.forecast_home
    data:
      type: daily
    response_variable: homeforecast

sensor:
  - name: Today High Temperature
    unique_id: today_high_temp
    device_class: temperature
    state: "{{ homeforecast['weather.forecast_home'].forecast[0].temperature }}"
    unit_of_measurement: °F
  - name: Today Low Temperature
    unique_id: today_low_temp
    device_class: temperature
    state: "{{ homeforecast['weather.forecast_home'].forecast[0].templow }}"
    unit_of_measurement: °F
#

Then just use the two variables today_low_temp and today_high_temp to set your automations for Above or Below those values.

obsidian bramble
#

congrats!