Skip to content

[FEATURE REQUEST] loading start and end date into helpers - solution #57

@VedeeM

Description

@VedeeM

possible solution for #24 , #47 , #55

I have made a small modification to the energy-period-selector-plus.js file

TIP: when changing a HACS .js file you also need to change the .js.gz file
Otherwise it seems you have a caching problem, But it is the original .js.gz file that is still used

The modification loads the start and end date into two helpers, every time the period selector plus changes.
Then the helpers can be used in any other card of HA

  1. Add code to energy-period-selector-plus.js
  2. Create the altered energy-period-selector-plus.js.gz file
  3. Add helper input_datetime.energy_start_date
  4. Add helper input_datetime.energy_end_date
  5. (optional) For use with apex-chart-card I added 2 extra helpers to calculate the span and offset out of the energy_start_date and energy_end_date

add following code to _setDate(t, e) in energy-period-selector-plus.js

        // === BEGIN MODIFICATIONS ===
    // Debugging logs
    console.log("Updating start_date:", t.toISOString().split('T')[0]);
    console.log("Updating end_date:", n ? n.toISOString().split('T')[0] : "No end date");

    // Update Home Assistant helpers
    try {
        this.hass.callService('input_datetime', 'set_datetime', {
            entity_id: 'input_datetime.energy_start_date',
            date: t.toISOString().split('T')[0], // Extract date in YYYY-MM-DD format
        });

        if (n) {
            this.hass.callService('input_datetime', 'set_datetime', {
                entity_id: 'input_datetime.energy_end_date',
                date: n.toISOString().split('T')[0], // Extract date in YYYY-MM-DD format
            });
        }
    } catch (error) {
        console.error("Error updating input_datetime helpers:", error);
    }
        // === END MODIFICATIONS ===

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions