Skip to content

Problem setting value to a variable #114

@Web-Spyder

Description

@Web-Spyder

I have set up multiple variables which work perfect. However there is one variable (see config below) which I'm not able to set its value using the service request.

Entry in my variable YAML-file:

pv_daily_production:
  unit_of_measurement: Wh
  unique_id: 34823482842848284
  value_template: >-
    {% if has_value('sensor.system_pv_total_power') and (states('sensor.system_pv_total_power') | float) > 0 %}
      {{ (states('sensor.system_pv_today_production') | float) * 1000 }}
    {% else %}
      {{ states('var.pv_daily_production') }}
    {% endif %}
  tracked_entity_id:
    - sensor.system_pv_today_production

I'd like to set the variable var.pv_daily_production to 0 at midnight and use a service call in an automation.

Action-Part of my automation:

service: var.set
data:
  entity_id: var.pv_daily_production
  value: 0

But this is not working. Trying to set the variable directly from the services menu does not work either. However, using the python set.state script, I can change the variable at midnight

service: python_script.set_state
data_template:
  entity_id: var.pv_daily_production
  state: "{{ 0 }}"

I'm not sure if I'm doing something wrong or why setting explicitly this variable does not work. Other variables I set in the same automation are changed like intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions