(1) What is the difference between
states.sensor.WaterPressureIDTS.state
and
states(‘sensor.WaterPressureIDTS’)
(2) Is there any restrictions on how you can use another sensor state with a template sensor?
(3) I am setting a sensor with now() but when I use that sensor again in another sensor the value is unknown or unavailable. I have cut the code down to this snippet below.
The entity value of Water Pressure TS is 2023-06-07 01:59:07.443554+02:00
but then WaterSTAT is Unavailable and WaterSTAT2 is Unknown
´´´
- name: Water Pressure TS
unique_id: WaterPressureIDTS
state: >
{{ now() }}
- name: Water STAT
unique_id: WaterSTAT
state: >
{{ states.sensor.WaterPressureIDTS.state }}
- name: Water STAT2
unique_id: WaterSTAT2
state: >
{{ states('sensor.WaterPressureIDTS') }}
If the sensor is valid, both will return the value. But if there’s a problem with the sensor or maybe it loads late, the first one will cause an exception and then the template sensor might not ever load. The second one is the preferred way to get a sensor value, because it will always return something even if the sensor is invalid.
Amazing. I simplified it down to this ultra basic code and it works. Thanks. Annoyingly fickle this environment.
´´´
- name: waterpressurets
unique_id: waterpressurets
state: >
{{ now() }}
- name: waterdup
unique_id: waterdup
state: >
{{ states(‘sensor.waterpressurets’) }}
´´´
@Didgeridrew I think I am going crazy. It does not work anymore. I have tried about 50 different ways! waterpressuredup is always unknown. Here is the entire first part of the template include file.
´´´
@pkscout I think I am going crazy. It does not work anymore. I have tried about 50 different ways! waterpressuredup is always unknown. Here is the entire first part of the template include file.
´´´
I don’t see anything glaringly wrong with you configuration, but it’s hard to tell for sure when it isn’t formatted correctly. This is most likely just a quirk of load order… when you chain two sensors like that and have them under the same trigger, you can get strange behavior. If you reload your template entities the second one will likely start working.
- trigger:
- platform: state
entity_id: sensor.serial_instruments
sensor:
- name: Water Pressure IDTS
unique_id: water_pressure_idts
state: >
{{ now() }}
- name: Water Pressured Up
unique_id: water_pressured_up
state: >
{{ states('sensor.water_pressure_idts') }}