Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem setting value to a variable #114

Open
Web-Spyder opened this issue May 10, 2024 · 2 comments
Open

Problem setting value to a variable #114

Web-Spyder opened this issue May 10, 2024 · 2 comments

Comments

@Web-Spyder
Copy link

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 added a commit that referenced this issue May 10, 2024
Switch to write_ha_state to address #114.
@snarky-snark
Copy link
Owner

Does var.set work again in v0.15.4?

@Web-Spyder
Copy link
Author

I saw you released 0.15.5. It is working! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants