Open HACS-bank opened 7 months ago
How come it is not unique? In any case, you can change your sensor name using the custom names functionalities (see the docs) and then you will surely have unique ID names.
UniqueIDs, is a feature of the Home assistant registry for individual entries, which is supposed to be set by the creating integration, in our case this should be EMHASS.
EMHASS doesn't correctly set these uniqueIDs so I would request this issue be reopened pending further investigation.
Reopened. I just thought that this was easily solved by a user-provided unique custom ID. I don't how this can be automatically set within EMHASS. But there is maybe an option that I don't know of.
unique_id can be registered at the same time as the entity creation:
https://developers.home-assistant.io/docs/entity_registry_index
_Any entity that is added to Home Assistant which specifies the unique_id attribute will be registered in the registry._
Unique ID of last resort For entities that are setup by a config entry, the Config Entry ID can be used as a last resort if no other Unique ID is available.
Just an update to this. I cant seem to find any possibility of adding a unique_id
via a REST call. This seems to be a issue a few people have come across, the only solution, so far, I can find is setting each sensor into the configuration.yaml before REST API POST. Please let me know if this changes.
I don't know if the POST /api/states/<entity_id>
endpoint accepts the unique_id
key in the JSON?
It is not listed as an option on the documentation: https://developers.home-assistant.io/docs/api/rest/
I don't know if the
POST /api/states/<entity_id>
endpoint accepts theunique_id
key in the JSON? It is not listed as an option on the documentation: https://developers.home-assistant.io/docs/api/rest/
I agree, I hope this could be change in the future, or separate rest call option to generate a sensor with a unique_id
first.
How come it is not unique? In any case, you can change your sensor name using the custom names functionalities (see the docs) and then you will surely have unique ID names.
Following actual documentation below is NOT working:
rest_command:
emhass_publish_data:
url: http://localhost:5000/action/publish-data
method: POST
content_type: "application/json"
timeout: 30
payload: >-
{
"custom_batt_forecast_id": {
"entity_id": "sensor.p_batt_forecast",
"unit_of_measurement": "W",
"friendly_name": "EMHASS Battery Power Forecast",
},
"custom_load_forecast_id": {
"entity_id": "sensor.p_load_forecast",
"unit_of_measurement": "W",
"friendly_name": "EMHASS Load Power Forecast",
},
}
2024-11-12 17:44:00,455 - web_server - INFO - Passed runtime parameters: {'pv_power_forecast': [0.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 127, 225, 355, 504, 614, 684, 730, 730, 694, 633, 540, 430, 274, 179, 101, 46, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'load_cost_forecast': [0.5779, 0.46775, 0.46775, 0.40352, 0.40352, 0.37706, 0.37706, 0.35657, 0.35657, 0.34861, 0.34861, 0.33716, 0.33716, 0.33902, 0.33902, 0.33255, 0.33255, 0.32795, 0.32795, 0.32748, 0.32748, 0.33126, 0.33126, 0.34122, 0.34122, 0.35562, 0.35562, 0.3957, 0.3957, 0.4679, 0.4679, 0.47025, 0.47025, 0.43856, 0.43856, 0.41107, 0.41107, 0.39119, 0.39119, 0.39247, 0.39247, 0.38989, 0.38989, 0.39667, 0.39667, 0.41176, 0.41176, 0.41194, 0.41194, 0.40655, 0.40655, 0.39214, 0.39214, 0.34862, 0.34862, 0.33629, 0.33629, 0.33469, 0.33469, 0.32649], 'prediction_horizon': 43, 'soc_init': 0.7, 'soc_final': 1.0, 'def_total_hours': [0, 0], 'alpha': 1, 'beta': 0, 'continual_publish': False}
2024-11-12 17:44:00,456 - web_server - INFO - >> Setting input data dict
2024-11-12 17:44:00,456 - web_server - INFO - Setting up needed data
2024-11-12 17:44:00,457 - web_server - INFO - Retrieve hass get data method initiated...
2024-11-12 17:44:06,707 - web_server - INFO - Retrieving weather forecast data using method = list
2024-11-12 17:44:06,708 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2024-11-12 17:44:06,708 - web_server - INFO - Retrieve hass get data method initiated...
2024-11-12 17:44:20,346 - web_server - INFO - >> Performing naive MPC optimization...
2024-11-12 17:44:20,347 - web_server - INFO - Performing naive MPC optimization
2024-11-12 17:44:20,350 - web_server - INFO - Perform an iteration of a naive MPC controller
2024-11-12 17:44:20,372 - web_server - DEBUG - Deferrable load 0: Proposed optimization window: 0 --> 0
2024-11-12 17:44:20,372 - web_server - DEBUG - Deferrable load 0: Validated optimization window: 0 --> 0
2024-11-12 17:44:20,430 - web_server - INFO - Status: Optimal
2024-11-12 17:44:20,430 - web_server - INFO - Total value of the Cost function = -9044.47
2024-11-12 17:44:20,578 - web_server - WARNING - Unable to parse runtime parameters
2024-11-12 17:44:20,578 - web_server - INFO - >> Setting input data dict
2024-11-12 17:44:20,579 - web_server - INFO - Setting up needed data
2024-11-12 17:44:20,580 - web_server - INFO - >> Publishing data...
2024-11-12 17:44:20,580 - web_server - INFO - Publishing data to HASS instance
2024-11-12 17:44:20,588 - web_server - INFO - Successfully posted to sensor.p_pv_forecast = 0.0
2024-11-12 17:44:20,593 - web_server - INFO - Successfully posted to sensor.p_load_forecast = 1879.53
2024-11-12 17:44:20,598 - web_server - INFO - Successfully posted to sensor.p_pv_curtailment = 0.0
2024-11-12 17:44:20,628 - web_server - INFO - Successfully posted to sensor.p_hybrid_inverter = 1879.53
2024-11-12 17:44:20,638 - web_server - INFO - Successfully posted to sensor.p_deferrable0 = 0.0
2024-11-12 17:44:20,645 - web_server - INFO - Successfully posted to sensor.p_batt_forecast = 1879.53
2024-11-12 17:44:20,654 - web_server - INFO - Successfully posted to sensor.soc_batt_forecast = 63.04
2024-11-12 17:44:20,663 - web_server - INFO - Successfully posted to sensor.p_grid_forecast = 0.0
2024-11-12 17:44:20,669 - web_server - INFO - Successfully posted to sensor.total_cost_fun_value = -9.04
2024-11-12 17:44:20,673 - web_server - INFO - Successfully posted to sensor.optim_status = Optimal
2024-11-12 17:44:20,679 - web_server - INFO - Successfully posted to sensor.unit_load_cost = 0.5779
2024-11-12 17:44:20,684 - web_server - INFO - Successfully posted to sensor.unit_prod_price = 0.08
Something similar to https://github.com/bramstroker/homeassistant-powercalc/pull/2708 would be needed to generate the required UUID for EMHASS.
I'm not sure if only integrations can generate UUIDs in this fashion, or if Add-On's can also generate entities in this manner.
Using core emhass version: 0.8.6
In the HA user interface, the settings dialog for e.g. sensor.p_pv_forecast can be accessed but produces the message:
_This entity ('sensor.p_pv_forecast') does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail._
This makes it harder for a user to e.g. put the EMHASS data into an "Area" in HA and put onto dashboards etc.