ok ill try that
i never found anything like that … and i appreciate the help so far
ok ill try that
i never found anything like that … and i appreciate the help so far
still not working all 4 sensors come up as unavailable even though the sensors they supposed to read from 3 of them have a value…
something else i should try? i checked the logs i didnt see no error there …
The only issue I can see off-hand is it that the sensor for weather condition, sensor.peterborough_current_condition
, reports it’s state with the “pretty” format “Mostly Cloudy” instead of one of the normal condition names like “partlycloudy”. This shouldn’t cause the issue you’re inquiring about, but it does mean that the template needs to be adjusted. The keys in the dictionary, mapper
, need to match the value returned by the entity used in condition
.
Copy the configurations for all the state-based sensors, paste it into the Template tool in Developer Tools, then let us know what it returns.
i guess thats why i have that {else} in the code i edited twice if it doesnt come up with any of those words then icon will be 12
glitch with website my post dis appearted… but i was saying the code i had and edited twice… has an else so if non of them words show then the icon will be number 12
and is there a way its always annoyed me… the weather updates i think like every 10 min but with my poor internet it always goes unaviable… anything to fix that?
so i did a test… i changed things around the names…cuz i needed them to match the names orginally i had for sensor like sensor.today_max … so what i did was i deleted the 4 sensors in the Devices section…
i renamed you see below… and i rebooted fully… when i check the states… it doesnt actually create the sensors…
- sensor:
- name: today_min
friendly_name: Today's mimimal temperature
unique_id: today_min
states: "{{ states('sensor.peterborough_low_temperature' ) }}"
availability: "{{ has_value('sensor.peterborough_low_temperature') }}"
- name: today_max
friendly_name: Today's maximal temperature
unique_id: today_max
state: "{{ states('sensor.peterborough_high_temperature' ) }}"
availability: "{{ has_value('sensor.peterborough_high_temperature') }}"
- name: today_rain
friendly_name: Today's rain forecast
unique_id: today_rain
state: "{{ states('sensor.peterborough_chance_of_precipitation') }}"
availability: "{{ has_value('sensor.peterborough_chance_of_precipitation') }}"
- name: today_icon
friendly_name: Today weather forecast
unique_id: today_icon
state: >-
{% set condition = states("sensor.peterborough_current_condition") %}
{% set mapper = {'clear-night': 3,
'cloudy': 5, 'fog': 16, 'hail': 6,
'lightning': 13, 'lightning-rainy': 17, 'partlycloudy': 8,
'pouring': 18, 'rainy': 9, 'snowy': 11,
'snowy-rainy': 7, 'windy': 14, 'windy-variant': 14 } %}
{{ mapper[condition] if condition in mapper.keys() else 12 }}
availability: "{{ has_value('weather.peterborough_forecast') }}"
so maybe its not right to create the sensor?
friendly_name
is not a valid configuration variable in the current format.
If you want the name and entity ID to be different you can change them in the UI.
ah ok… i took out the friendly name… and reboot HA but it didnt create the sensors still all i did above just ## pound them out… and restarted… so still wont make those sensors
must be something just 1 small thing
You need to just delete everything… I think you’ve got stuff that is not properly commented out and it’s causing the file to not be loaded properly or you have unique IDs that aren’t unique…
I added the Environment Canada integration to my instance, pasted the sensor config from my post above, and this is the result:
template:
- trigger:
- platform: time_pattern
hours: /1
- platform: homeassistant
event: start
action:
- service: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.peterborough_forecast
response_variable: hourly
- variables:
ptb_forecast: "{{ hourly['weather.peterborough_forecast'].forecast }}"
sensor:
- name: Temperature forecast next hour
unique_id: temperature_forecast_next_hour
state: "{{ ptb_forecast[0].temperature }}"
unit_of_measurement: °C
attributes:
forecast_0: "{{ ptb_forecast[0] }}"
- sensor:
- name: Today Min
unique_id: todays_minimal_temperature_0001
state: "{{ states('sensor.peterborough_low_temperature' ) }}"
availability: "{{ has_value('sensor.peterborough_low_temperature') }}"
- name: Today Max
unique_id: todays_maximal_temperature_0001
state: "{{ states('sensor.peterborough_high_temperature' ) }}"
availability: "{{ has_value('sensor.peterborough_high_temperature') }}"
- name: Today Rain
unique_id: todays_rain_forecast_0001
state: "{{ states('sensor.peterborough_chance_of_precipitation') }}"
availability: "{{ has_value('sensor.peterborough_chance_of_precipitation') }}"
- name: Today Icon
unique_id: today_condition_icon_0001
state: >-
{% set condition = states("weather.peterborough_forecast") %}
{% set mapper = {'clear-night': 3,
'cloudy': 5, 'fog': 16, 'hail': 6,
'lightning': 13, 'lightning-rainy': 17, 'partlycloudy': 8,
'pouring': 18, 'rainy': 9, 'snowy': 11,
'snowy-rainy': 7, 'windy': 14, 'windy-variant': 14 } %}
{{ mapper[condition] if condition in mapper.keys() else 12 }}
availability: "{{ has_value('weather.peterborough_forecast') }}"
FWIW, in your post in the other thread you are using value_template
which is not a valid configuration variable in the current format.
its finally working yaaaaa… what i ended up doing… was i removed the weather.yaml and rebooted HA and then i checked states… and i seen the sensors were still there and the temp ones from i was making… so i i went to settings devices and entities… and searched for them. and deleted them… and did another reboot… check for sensors just to see if anything… conflicting… and then i put the weather.yaml back… and rebooted… and this time it worked… i guessing something was stuck and wouldnt fix itself… so seems to be working…
what does FWIW mean?
and ya i put back state: as value:template i trying something… i did find if i put it under the weather trigger automation under the sensor… it wouldnt work for me… it but id have to keep it under the - sensor:
another question… i tried
### Today's rain forecast ###
- name: today_rain
state: "{{ states('sensor.peterborough_chance_of_precipitation') | Default(0)}}"
availability: "{{ has_value('sensor.peterborough_chance_of_precipitation')}}"
but since thats wrong what is the right code when its unavalable… the value should be 0
For what it’s worth
If you want it to report 0 even if the source sensor is unavailable or unknown then you can remove the availability
. Also, Default()
is not a valid filter function. Case matters; the filter is default()
.
### Today's rain forecast ###
- name: today_rain
state: "{{ states('sensor.peterborough_chance_of_precipitation') | int(0) }}"
If you want to be able to edit the entities’ names or IDs in the UI you will need to give them unique IDs.
ok cool ill try those and learn something new everyday FWIW (:
so i removed the default… and i removed the avaliablity but it still made the sensor unknown… or do i need that default in there?
Sorry about that… default()
is for undefined values, but when the source sensor returns “unknown” or “unavailable” those values are considered defined. You will need to use a different method. Since this is for a numerical value I would suggest int(0)
or float(0)
…
### Today's rain forecast ###
- name: today_rain
state: "{{ states('sensor.peterborough_chance_of_precipitation') | int(0) }}"
ok that works. thanks learn something new everyday… glad you know all this code… you must deal with it every day…
i know i still wanna do i asked a year or 2 ago but i still wanna do it … i wanna make a sensor with multiple attributes. like the weather sensor… but no one ever got back to me… i wanted it it for a mqtt and also for a couple things like a message to a display screen… so message had title font color message but no one ever knew… do you know how that works… not something i wanna work on today… but if you know could point me in the right direction for that
I don’t use MQTT very much, but it’s going to depend on how the MQTT topic and payload are set up and/or where the different data points are coming from. If the values for the sensor’s state and all the attributes all come from MQTT, then use an MQTT sensor otherwise you may need to create multiple sensors.
The devil is in the details.
I don’t understand what you are asking about.
sooo what i asked couple years ago is
weather forecast… has attributes
condition
temperature
wind
etc
i wanted to make a sensor called like
display_message:
with attributes
title
font
color
message
this way instead of having 4 sensors i could have 1 sensor with 4 attributes… but when i asked no one ever knew how to do it… so no one could help me
so i was going to MQTT a message, and then id also mqtt message stating the Title or Font and it go in that 1 sensor just like the Weather sensor
so the 4 fields would go into 1 sensor…
right now how i do it is i have multiple Sensors… and in Esphome i then send a certain Title, font color, and message to Nexition screen… but wanted it all from 1 sensor so i could change it…from a sensor… right now i have to edit Esphome and change it in the code.
so id like
sensor.message_display
-attribute 1: title
-attribute 2: message
-attribute 3: font title
-attribute 4: font message
-attribute 5: title color
-attribute 6: message color
and then id like to do how you read the fields like weather to seperate them
as i wanna change it in my esphome code to make it universal instead of this
lambda: |-
id(nextion1).goto_page("2");
id(nextion1).set_component_text("title","Warning");
id(nextion1).set_component_text("wmessage",id(warning_message).state.c_str());
and
- lambda: |-
id(nextion1).goto_page("2");
id(nextion1).send_command_printf("title.pco=2016");
id(nextion1).set_component_text("title","Incoming...");
id(nextion1).set_component_text("wmessage",id(caller_id_displayid).state.c_str());
i have other ones but those just couple examples
but at the time no one knew how to do the weather forecast… so i shelved things
its something id still like to learn to do if possible but if you dont know thats ok too… cuz no one at the time knew… least i couldnt find help… as i had some other ideas too i wanted to use 1 sensor with multiple values but i forgotten for what now lol