snarky-snark / home-assistant-variables

A custom Home Assistant component for declaring and setting generic variable entities dynamically.
Apache License 2.0
278 stars 16 forks source link

Problem setting value to a variable #114

Open Web-Spyder opened 5 months ago

Web-Spyder commented 5 months ago

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.

snarky-snark commented 5 months ago

Does var.set work again in v0.15.4?

Web-Spyder commented 5 months ago

I saw you released 0.15.5. It is working! Thanks