Everything you’ve described so far, notably the two sources of truth, is handled by what I had suggested above.
okay tested so:
Inverter to HA UNIX time
Human 12 hour helper time to HA UNIX to Inverter
HA UNIX Time to Human helper time
Write a second automation.
If you recall, in a previous post I suggested you create a second automation to handle that.
Easy peasy.
Thanks both.
So I have used @123 example and flipped the number.lux_ac_charge_end1
and the input_datetime.lux_ac_charge_end_2 in all entries.
I assume I now need to find an equation to take the raw data and convert it into HH:MM AM/PM ?
@123 Easy peasy may not come in to it.
I am still learning all this coding so let me share what I have done - all probably wrong. But still can’t get it to work
alias: Lux- AC Charge End 2 test from Lux to HA
description: ""
trigger:
- platform: state
entity_id:
- number.lux_ac_charge_end1
condition:
- condition: template
value_template: "{{ states(n)|int(0) != t }}"
action:
- service: input_datetime.set_datetime
target:
entity_id: "{{ n }}"
data:
value: "{{ t }}"
mode: single
variables:
i_d: number.lux_ac_charge_end1
"n": input_datetime.lux_ac_charge_end_2
t
Can’t get t to work, it is looking for a date/time. I have tried changing data value to data:time and tried calling a service to change t to a time but not sure how to do this.
Thanks for your patience.
Any help would be wonderful.
OKay got somewhere with the code but getting:
Stopped because an error was encountered at August 9, 2022 at 4:55:55 PM (runtime: 0.07 seconds)
Invalid time specified: ‘03:08:AM for dictionary value @ data[‘time’]
Also - the time it is picking up is wrong- it should be 2:30 am
id: '1660004595263'
alias: Lux- AC Charge End 2 test from Lux to HA
description: ''
trigger:
- platform: state
entity_id:
- number.lux_ac_charge_end1
condition:
- condition: template
value_template: '{{ states(n)|int(0) != t }}'
action:
- service: input_datetime.set_datetime
target:
entity_id: '{{ n }}'
data:
time: '{{ t }}'
mode: single
variables:
i_d: number.lux_ac_charge_end1
'n': input_datetime.lux_ac_charge_end_2
t: >-
‘{{ states.number.lux_ac_charge_end1.state | int |
timestamp_custom("%-I:%M:%p")}}
My inverter sends data of the UNIX time for schedules but it is attached to a number entity
e.g. number.lux_ac_charge_end1
I have managed to work with @123 to write a code to convert HH:MM to Unix but I am struggling to get it to write Unix to HH:MM:SS as the entity in number? I can get the code to work if manually populating the data so I know it is something to do with the taking of the data from the entity beginning number and using it to create the time.
I have spent two days reading and I might have to convert number??
Please help
alias: "!TEST"
description: ""
trigger:
- platform: state
entity_id: number.lux_ac_charge_end1
condition:
- condition: template
value_template: "{{ states(n)|int(0) != t }}"
action:
- service: input_datetime.set_datetime
target:
entity_id: "{{ n }}"
data:
timestamp: "{{ t }}"
variables:
i_d: number.lux_ac_charge_end1
"n": input_datetime.lux_ac_charge_end_2
t: "THIS IS THE BIT I CAN'T FIGURE OUT"
mode: single
The template editor (along with the documentation) is your friend:
{{ as_datetime( states('number.lux_ac_charge_end1') ).strftime('%H:%M:%S') }}
Thanks @tom_l
It is now sending data between unix and helper so one step forward.
The data it translates is the data it is given but it is not correct.
I am thinking it is a time zone thing?
So
Input to inverter is 03:30
Unix data sent to HA is 7683.0
Using an online unix converter that is 02:08
Time displayed in helper is 02:08
So something wrong with the data coming in?
Thanks so much for the help.
{{ as_local(as_datetime(states('number.lux_ac_charge_end1'))).strftime('%H:%M:%S') }}
Thanks for th support so far, I feel this is beyond me as I have just realised that the coding to go from HH:MM:SS to computer format shows it is not unix but a calculation.
id: '1659465742926'
alias: Lux- AC Charge End 2
description: ''
trigger:
- platform: state
entity_id: input_datetime.lux_ac_charge_end_2
variables:
i_d: input_datetime.lux_ac_charge_end_2
n: number.lux_ac_charge_end1
t: "{{ state_attr(i_d, 'minute')|int(0) * 256 + state_attr(i_d, 'hour')|int(0) }}"
condition: '{{ states(n)|int(0) != t }}'
action:
- service: number.set_value
target:
entity_id: '{{ n }}'
data:
value: '{{ t }}'
mode: single
Now simply put, one would reverse the t
variables to produce the output in reverse possible by also changing the action, service
and the data
type to timestamp
but that is where my logic finishes and my coding has dried up.
It would be great if you could help me complete this and give me the reasoning why so I can see what and why it is the way it is.
Thanks