Utility and automation

Hello,

I’m try to track when my car is charged by sun or grid but i have some trouble to have autoamtion work.
The sensor “charge_type” is working properly but automation not.

I have following error if I try to execute the action of the automation
Error: “Option “sun” is not valid for entity select.energy_ecar_from_grid_or_sun, valid options are: sun, grid, other”.

someone understand the problem?

utility_meter:
  energy_ecar_from_grid_or_sun:
    source: sensor.presa_ricarica_auto_energy
    cycle: daily
    tariffs:
      - sun
      - grid
      - other

template:
  - sensor:
      - name: "charge type"
        unique_id: charge_type
        state: >-
            {% if (states('sensor.home_consumption_power') | float(0) > 0) %}
              "grid"
            {% elif (states('sensor.home_consumption_power') | float(0) < 0) %}
              "sun"
            {% else %}
              "other"
            {% endif %}
automation:
  - id: "set_grid_or_sun_consumption"
    alias: "Set Grid or Sun consumption"
    trigger:
      - platform: state
        entity_id: sensor.charge_type
    action:
      - service: select.select_option
        data_template:
          option: "{{ states('sensor.charge_type') }}"
        target:
          entity_id: select.energy_ecar_from_grid_or_sun
    mode: single

Remove the double-quotes (because if you include them, they become part of the string).

        state: >-
            {% if (states('sensor.home_consumption_power') | float(0) > 0) %}
              grid
            {% elif (states('sensor.home_consumption_power') | float(0) < 0) %}
              sun
            {% else %}
              other
            {% endif %}

Thank you!

1 Like