I’m working on an interface between Home Assistant on my RV and my Victron Venus OS running on a Pi. Much of it is coming together pretty well but I’m having a problem converting the generator Quiet Hours to and from the time helper in HA.
Victron stores the time as the number of seconds for a 24 hour period (0 to 86400) as the Quiet Time Start and Quiet Time End. I can get those values from the using MQTT.
The time values need to be in sync and only change when we drive to a new campsite and they have different quiet time hours for generator use. I typically will update the Quiet Time start and end hours in HA and the goal is to update those times in the Victron system so the generator does not start during quiet time.
- name: "Quiet Hours Start"
unique_id: "quiet_hours_start"
state_topic: "victron-rv/N/device_id/settings/0/Settings/Generator0/QuietHours/StartTime"
value_template: >
{{ value_json.value | int(0) }}
{% set quiet_time_start = value_json.value %}
{% set quiet_time_start_min = ((quiet_time_start % 3600) / 60) | int %}
{% set quiet_time_start_hour = ((quiet_time_start % 86400) / 3600) | int %}
- name: "Quiet Hours End"
unique_id: "quiet_hours_end"
state_topic: "victron-rv/N/device_id/settings/0/Settings/Generator0/QuietHours/EndTime"
value_template: >
{{ value_json.value | int(0) }}
{% set quiet_time_end = value_json.value %}
{% set quiet_time_end_min = ((quiet_time_end % 3600) / 60) | int %}
{% set quiet_time_end_hour = ((quiet_time_end % 86400) / 3600) | int %}
In the template sandbox under developer tools the numbers are close working but I’m having problems with the correct syntax to get the conversion working. I’ve imitated the json values I receive from MQTT to debug the code.
I’ve created two input time helpers in HA. I need to set these time input helpers (to HH:MM:00) when the start time (from seconds) is changed in the Victron system. And I need to convert these time helper variables (from HH:MM) to seconds and write that to to the Victron system when the time helpers are changed in HA.
{## Imitate available variables: ##}
MQTT VARIBLES (testing json received from Venus)
{% set json_quiet_time_starttime = {"max":86400,"min":0,"value":75600} %}
{% set json_quiet_time_endtime = {"max":86400,"min":0,"value":21600} %}
Quiet End Time (in seconds) is {{ json_quiet_time_endtime.value }}.
{% set quiet_time_end = json_quiet_time_endtime.value %}
{% set quiet_time_end_hour = ((quiet_time_end % 86400) / 3600) | int %}
{% set quiet_time_end_min = ((quiet_time_end % 3600) / 60) |int %}
Quiet Start Time (in seconds) is {{ json_quiet_time_starttime.value }}.
{% set quiet_time_start = json_quiet_time_starttime.value %}
{% set quiet_time_start_hour = ((quiet_time_start % 86400) / 3600) | int %}
{% set quiet_time_start_min = ((quiet_time_start % 3600) / 60) | int %}
Quiet End Time Hour: {{ quiet_time_end_hour }}
Quiet End Time Min: {{quiet_time_end_min}}
Quiet End Time Sec: 00
Quiet Start Time Hour: {{ quiet_time_start_hour }}
Quiet Start Time Min: {{quiet_time_start_min}}
Quiet Start Time Sec: 00
TIME HELPER VARIABLE
Quiet Time End: {{ states('input_datetime.quiet_hours_end_time_helper') }}
Quiet Time Start: {{ states('input_datetime.quiet_hours_start_time_helper') }}
***RESULTS***
Result type: string
MQTT VARIBLES (testing json received from Venus)
Quiet End Time (in seconds) is 21600.
Quiet Start Time (in seconds) is 75600.
Quiet End Time Hour: 6
Quiet End Time Min: 0
Quiet Start Time Hour: 21
Quiet Start Time Min: 0
TIME HELPER VARIABLE
Quiet Time End: 07:00:00
Quiet Time Start: 21:30:00
To start, looking for help converting the Time helper variables to be in seconds from (0 to 86400). Eventually I hope to take the seconds from Victron and update the Time Helper variables.