I’m trying to do something similar to the thread below.
I have a helper in HA with an opening and closing time I’d like esphome to read the value, store it into a global variable and then perform automations based on the values. This is for cases where the connection to HA is not working when the automation is triggered.
Below is the code I’m using just to print the value in esphome however no value is ever published even when I change the value in the helper.
Alternatively I also have a bit of code that just publishes the value of open_time_temp every 10 seconds however the value is stuck at 1073453424 ( I presume this is default value assigned).
time: #time triggers to open and close the door in case the wifi is turned off at night
- platform: homeassistant
id: ha_time
on_time:
- seconds: /10
minutes: /1
then:
- logger.log:
format: "values %d "
args: [ 'id(open_time_temp)' ]
Any help would be appreciated as I’m slowly loosing my mind!
Is datetime actually a valid attribute of an input date/time?
I think the attribute you need is timestamp, which for an input that accepts just a time (as opposed to a date or date & time) returns the number of seconds since midnight.
So you’re right! Started trying different attribute types and got lucky, its a bit tricky that there is no list of them for esphome (at least none I could find anyway).
Went absolutely cacked trying to figure that out.
Thought I’d add my code in case someone else has a similar issue. Passing the data to a global was a bit unintuitive, I tried using the "then : - globals.set: " combo but couldn’t figure it out so went with a lambda
globals:
- id: open_time_sec
type: int
restore_value: no
initial_value: '28800' # 8am in seconds
- id: close_time_sec
type: int
restore_value: no
initial_value: '72000' # 8pm in seconds
sensor:
- platform: homeassistant
id: open_time_temp
entity_id: input_datetime.chicken_door_opening_time
attribute: timestamp
on_value:
then:
- lambda: |-
ESP_LOGD("main", "starttime value is: %d seconds", int(x));
id(open_time_sec) = int(x) - 5*60;
#set the global variable to the value set by the field. minus 5 minutes from it to give time for the system to boot up and connect if needed
- platform: homeassistant
id: close_time_temp
entity_id: input_datetime.chicken_door_closing_time
attribute: timestamp
on_value:
then:
- lambda: |-
ESP_LOGD("main", "starttime value is: %d seconds", int(x));
id(close_time_sec) = int(x) + 5*60;