snarky-snark / home-assistant-variables

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

Service var.set broken and do nothing after update to 0.15.1 #107

Closed gamba69 closed 5 months ago

gamba69 commented 5 months ago

Hello, after update to 0.15.1 service var.set silently do nothing. Variable value and attributes not updated, and I don't see any error in log.

estegewr commented 5 months ago

I encounter the same problems after updating to 0.15.1

snarky-snark commented 5 months ago

Do one of you mind trying out the latest develop release to see if that fixes the problem?

estegewr commented 5 months ago

Perhaps I used the module in a non-standard way. This is my config

var:
  callmon_caller_1:
    icon: mdi:phone
    value_template: "{{ now() }}"
    attributes:
      name: "{{ state_attr('sensor.fritz_box_7590_ui_call_monitor_telefonbuch', 'from_name') }} "
      number: "{{ state_attr('sensor.fritz_box_7590_ui_call_monitor_telefonbuch', 'from') }} "
      start: ""
      duration: ""

In the past, I was able to initiate the attributes start and duration with an empty value when I set the variable. It seems to be strange that I use the update call, but all value rules are defined in the configuration:

service: var.update
data:
  entity_id: var.callmon_caller_1

A few events later I would like to set the two attributes start and duration using the set call:

service: var.set
data:
  entity_id: var.callmon_caller_1
  attributes:
    duration: '00:00:11'

This doesn't work anymore for attributes that are "initiated" in the configuration. Interestingly I can set attributes which are not initiated in config. But thiese variables always get overwritten whenever I restart HA.

GaPhi commented 5 months ago

Same problem here : I had to remove the "initialization" in my var.yaml configuration file.

nm20220210 commented 5 months ago

downgrade to an old version in HA now

alias: vartest
description: ""
trigger: []
condition: []
action:
  - service: var.set
    data:
      entity_id: var.pmx152
      value: test
  - if:
      - condition: state
        entity_id: var.pmx152
        state: test
    then:
      - service: notify.persistent_notification
        metadata: {}
        data:
          message: OK
    else:
      - service: notify.persistent_notification
        metadata: {}
        data:
          message: NIO
mode: single
gamba69 commented 5 months ago

Do one of you mind trying out the latest develop release to see if that fixes the problem?

Checked. Now I have error: [ ... skipped ...] File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 905, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in _handle_entity_call result = await task ^^^^^^^^^^ File "/config/custom_components/var/init.py", line 448, in async_set await self.async_write_ha_state() TypeError: object NoneType can't be used in 'await' expression

and after I change "await self.async_write_ha_state()" -> "self.async_write_ha_state()"

all working fine.

snarky-snark commented 5 months ago

Thanks! I made the fix in v0.15.2.