andrew-codechimp / HA-Battery-Notes

A Home Assistant integration to provide battery notes of devices
MIT License
445 stars 83 forks source link

Cannot set last_changed date via service #1801

Closed chemelli74 closed 3 days ago

chemelli74 commented 4 days ago

System Health details

System Information

version core-2024.6.4
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.12.2
os_name Linux
os_version 4.4.302+
arch x86_64
timezone Europe/Rome
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4989 Installed Version | 1.34.0 Stage | running Available Repositories | 1390 Downloaded Repositories | 22
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Dashboards dashboards | 2 -- | -- resources | 12 views | 14 mode | storage
Recorder oldest_recorder_run | 19 giugno 2024 alle ore 19:53 -- | -- current_recorder_run | 28 giugno 2024 alle ore 19:17 estimated_db_size | 972.75 MiB database_engine | sqlite database_version | 3.44.2
Spotify api_endpoint_reachable | ok -- | --

Checklist

Describe the issue

Cannot set the last replace data via service. Call details:

service: battery_notes.set_battery_replaced
data:
  source_entity_id: sensor.sensore_1_cameretta_battery_last_replaced
  datetime_replaced: "2024-06-28 12:27:00"
  device_id: deef0ff3cb2886ea4b319d38fe6270c8

Device:

image

Reproduction steps

  1. configure device in battery notes
  2. hit button "replace battery"
  3. check value: all fine so far
  4. call "battery_notes.set_battery_replaced"
  5. check value: is still the old one
  6. check log: error reported

Debug logs

2024-06-29 16:12:39.480 ERROR (MainThread) [custom_components.battery_notes] Entity sensor.sensore_1_cameretta_battery_last_replaced not configured in Battery Notes

Diagnostics dump

No response

andrew-codechimp commented 4 days ago

source_entity_id is only used if you created an entity type battery note and should be set to the entity_id that battery notes is associated with. If your battery note is a more typical device type then setting the source_entity_id: "" should fix this.

service: battery_notes.set_battery_replaced
data:
  source_entity_id: ""
  datetime_replaced: "2024-06-28 12:27:00"
  device_id: deef0ff3cb2886ea4b319d38fe6270c8
chemelli74 commented 4 days ago

Confirmed to work fine with:

service: battery_notes.set_battery_replaced
data:
  datetime_replaced: "2024-06-28 12:27:00"
  device_id: deef0ff3cb2886ea4b319d38fe6270c8

Thank you !

I suggest you give a failure feedback to the UI when the settings are wrong. And improve the service description to help others.