teadragon7
(Teadragon7)
December 10, 2023, 2:56am
1
Hello! I got a time based sensor from an Integration that I am trying to offset by a few minutes.
I found the following topics but I am unsure how to combine them:
Hi everyone,
I’m struggling to make an automation where I turn on some lights after sunset, with an offset of some minutes. These would be selected quickly from an input_number, instead of going every time to change the automation. Link here the current automation and what I would do:
automation:
#Luci ON tramonto
- alias: Luci ON al tramonto
trigger:
- platform: sun
event: sunset
offset: "00:15:00"
condition:
- condition: state
entity_id: light.luce_led_rampa_g…
Hello,
I already used the search function and also found the thread https://community.home-assistant.io/t/add-temp-offset-with-sensor-template/16114 .
But I don’ t get it working.
How can I add a offset to my sensor data?
How can I hide the sensor DHT22 and only show the sensor value from the template?
From where do I get these entity_id, I found them in the database, is it the right way to get the names?
sensor:
- platform: dht
sensor: DHT22
pin: 4
monitored_conditions:
…
This is what I have so far:
sensor:
name: Time Test3
unique_id: time_test3
- platform: time
sensor: jewish_calendar_upcoming_candle_lighting_3
- platform: template
sensors:
jewish_calendar_upcoming_candle_lighting_3_offset:
value_template: '{{states.sensor.sensor.jewish_calendar_upcoming_candle_lighting_3.state | float - 00:30}}'
Any help would be much appreciated!
tom_l
December 10, 2023, 3:07am
2
For a start:
https://www.home-assistant.io/docs/configuration/templating/#states
What does this return in the Developer Tools → Template editor?
{{ states('sensor.jewish_calendar_upcoming_candle_lighting_3') }}
teadragon7
(Teadragon7)
December 10, 2023, 3:37am
3
@tom_l It returns a string “2023-12-15T20:58:00+00:00”
I don’t remember where I got it from but I saw that it might be needed to take the string and turn it into numbers, is the following along the right path?
state: = { strptime(states("sensor.jewish_calender_upcoming_candle_lighting_3), "%d/%m/%Y, %H:%M", "") - timedelta( minutes = 30 )}
tom_l
December 10, 2023, 3:55am
4
No not numbers. You can use it as a datetime object:
value_template: "{{ states('sensor.jewish_calendar_upcoming_candle_lighting_3')|as_datetime - timedelta(minutes = 30) }}"
Also note you should be using the new template integration for new sensors:
configuration.yaml
template:
- sensor:
- name: Jewish Calendar Upcoming Candle Lighting 3 Offset
state: "{{ states('sensor.jewish_calendar_upcoming_candle_lighting_3')|as_datetime - timedelta(minutes = 30) }}"
device_class: timestamp
I’m not sure what this is supposed to be:
sensor:
name: Time Test3
unique_id: time_test3
- platform: time
sensor: jewish_calendar_upcoming_candle_lighting_3
teadragon7
(Teadragon7)
December 10, 2023, 4:28am
5
Thank you! That worked great! Out of curiosity how would I add 30 minutes from the result rather than subtract?
tom_l
December 10, 2023, 4:40am
6
Change the minus sign to +
state: "{{ states('sensor.jewish_calendar_upcoming_candle_lighting_3')|as_datetime + timedelta(minutes = 30) }}"