enkama / hass-variables

Home Assistant variables component
89 stars 12 forks source link

A small question about calling service V2 vs V3 #80

Closed pickonedev closed 1 year ago

pickonedev commented 1 year ago

Hi!

I am still using the V2 addon and I am afraid of upgrading to V3 because I have more than 2000 lines in variable.yaml then more than 15000 lines in the automations.yaml which mor ethan 70% of them are using variables... and first, before doing something which can make me regret, I have a question about Calling Services...

Till now, the construction of calling a service was containing only "service:" and "data:"

service: variable.set_variable
data:
  variable: kitchen_fridge_ambient_temperature
  value: High

From the V3, I saw some changes, like "service", "data" and "target"...

    service: variable.update_sensor
    data:
      value: 30
    target:
      entity_id: sensor.test_timer

I need to know if I will change to V3, I need to change all the automations from the first code construction to the new one, or it will work with the old one as well? This is the hardest breaking change for me... In the variables.yaml I can do all with find&replace, but in automations... it will be harder.

Thank you!

Snuffy2 commented 1 year ago

The legacy services of variable.set_entity and variable.set_variable continue to work in v3 for Sensor Variables. If you are using variable.set_entity, you will need to change the entity from variable.<variable_id> to sensor.<variable_id>.

pickonedev commented 1 year ago

I have tried right now but I get error... Any idea?

Variable has been defined like this, into variable.yaml file

variable_last_state:
  value: ""
  restore: true

which means that I have a sensor.variable_last_state entity

image

With this is working to change the value

service: variable.update_sensor
data:
  value: ok
target:
  entity_id: sensor.variable_last_state

But I need to use the legacy version

Snuffy2 commented 1 year ago

Can you please show me the full error in the HA logs. I'm not able to identify what may be causing the error you are seeing.

pickonedev commented 1 year ago

Sorry, I can't now because today I finished with all the find and replace actions in order to change everything from the V2 to V3... But now I have another problem...

I have this variable defined, like many others...

variable_aqara_cube_battery:
  value: 100
  restore: true
  attributes:
    unit_of_measurement: "%"
    device_class: battery
    icon: mdi:battery
    string_state: initial

And every time after I restart HA, I get warnings like this 2023-07-12 23:38:25.891 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.variable_aqara_cube_battery (<class 'custom_components.variable.sensor.Variable'>) is using native unit of measurement 'None' which is not a valid unit for the device class ('battery') it is using; expected one of ['%']; Please update your configuration if your entity is manually configured, otherwise report it to the custom integration author.

I get 103 identical warnings, from many variables...

Any idea? I have even removed the unit_of measurement and device_class from variables and I still get 103 warnings after restart...

Snuffy2 commented 1 year ago

Change From: unit_of_measurement: "%"

To: native_unit_of_measurement: "%"