@Olen
Possibly when you get details about a plant, you can download/cache image into local folder and then refer to the local folder within component. Though, as the image can be updated on Cloud end then there should me way to re-fetch plant’s image_url from API and then new image using new URL again. The thing is in current implementation even if the url is the same the image can be different as the key to the image is pid (PlantID).
Also as users will be able to update and add more optimal environment thresholds, there should be way to refresh plant’s details from API.
I have not implemented any auto-download or local caching of images, which is why I default to a local path. It is easy enough to download the image to the correct path manually when you add a new plant.
I am going to do some more cleanup, and possibly wait for the API to settle a bit more(?) before submitting a PR to the plant component itself.
I am not sure I will implement a “refresh” function for this. The data is pulled from the API each time HA starts up, and I don’t think there will be that many changes to the values.
On the other hand, I am considering adding “config flow” to the plant component, so plants can be configured from the GUI. As of now, it would be quite complicated, as you would first need to add the API client_id and secret, and then add each plant by searching the API (with a fallback if no plant is found). And then be able to add the neccesary sensors…
For now I am pretty happy that all I need to configure is the species and sensors, and the rest is taken care of by the component.
I split out the openplantdb functions to a seperate integration, and made a config flow for setting up the API.
In the process I realized that the only reason this was necessary was that the API requires authentication. I am not sure why you require that for read only access, but that is another discussion…
I have also changed the plant component again, so it now takes advantage of this new openplantdb component if it is enabled and configured. This means less modifications to the plant component, and also that it could be possible to add other sources of information about plants as well, if that becomes an option later.
I’ll clean up the code some more, and add a PR for the openplantdb integration tomorrow. If (when) that is merged, I’ll add a PR to update the plant component as well.
Thank you. It always annoyed me that I had to configure the max/min values for each plant in every card or sensor or automation or whatnot, and I was really considering setting up such an API myself. However, it requires some infrastructure that I do not have time to maintain at the moment. So when @slaxor did that heavy lifting, it was a great opportunity to get this “right”.
The PR for the OpenPlantbook integration is now added:
I need to rewrite parts of it and get a openplantbook-python package published in pypi first… So it will take some more time tha initially thought.
@slaxor would it be acceptable to open the full API to everyone (read only), without having to use a client_id and secret?
It would greatly simplify the integration in HA, as we would not need a special integration just to configure the client_id and secret.
First of all, thank you @rlems for good words. I’m very glad to hear that we are bringing value to community and the product of our efforts is useful.
@Olen I’m really grateful for your contribution while enables myself and others to start using the api with home-assistant straight away.
Thank you for raising questions about anonymous read-only API access. There are number of reasons to require authentication, though the main ones are:
Cloud resources are limited and I’d like to spend them only on intended use. So API serve only users who is registered and understand what API for.
Another reason is security. What do I mean by that? If for example there is an DDOS attack on API or some API client misbehaves (the most likely scenario). Without authenticated access, I have no means to track the client and isolate it to prevent negative impact on API performance and cloud resources consumption.
In addition to this in near future, API will provide write access as well so it would be more difficult to segregate anonymous requests.
Having said that I understand that authentication always brings extra layer of complexity and because of that I’m making it as simple as possible to users and developers to register and get credentials. There is potentially room for improvement here and I’m happy to implement whatever necessary to make it even easier.
I hope it makes sense and understandable. Nevertheless, I’m open to any suggestions.
I fully understand your points.
The issue is that since we need to store the client id and secret in HA, I have to create a new integration for openplantbook. However, since this integration does not provide any devices or services or entities, it sort of breaks the standard for an integration.
Without the need to store any config (client id and secrets), I could add the openplantbook api directly to the plant integration.
But I will see what the devs have to say about the openplantbook integration, and if they accept it even if it breaks some conventions.
I’m absolute novice at HASS development at this stage but logically I’d assume that openplantbook component should include all the communications call to the API and expose “species” as a service. I don’t know if I’m right here or it is too complicated to implement but I’d imagine ideally reference to a plant could be like:
OpenPlantbook component in return would expose plant details to the plant components.
However, I see that there could be challenge with Plant-ID but I’m happy to work it through on API end.
BTW, I have plans to clean up {pid} Plant-ID in Database and get rid of all non-letter characters such as quotes and dots and possibly spaces. It’d love to hear your opinion about this, guys.
Thanks in advance!
With that in place, it is also possible to imagine something like a Lovelace card where you can search the Openplantbook and display the results. And from there it is possible to move on to create a way to configure new plants directly from the GUI.
But first and foremost I need to get the Openplantbook PR correct and added to core.
Ideally I don’t want any direct dependencies or references to the Openplantbook integration in the config of the plants. So the Plant integration will (hopefully) accept like:
plant:
plant_1:
species: champagne mini rose
sensors:
moisture: sensor.mi_m_80eaca88xxxx
And then I have a simple check in the init of the Plant integration to check if the Openplantbook integration is set up, and if it is, the Plant integration will use the Openplantbook integration get the config-data for each spieces.
Cleaning up the pids sounds like a good idea, as long as they are still unique.
Someone just got a PR for adding the configured min/max-values to the attributes of the plant entities accepted:
That is one of the steps required to have the openplantbook component do something something useful, so that is good.
The next steps are to add a two more config entries and attributes (“species” and “image”) to the plant integration and then finally include the data from the openplantbook integration if it is set up.
That’s a very cool hack @Olen! I’m impressed how quickly you deliver those!
I’m wondering if HASS web UI have enough features to support plant editing UI in future and potentially plant/sensor binding as well so it will be possible to edit Plant DB directly in HASS UI w/o editing HASS config. And you can bind sensors to different plants in case you move one sensor from one plant to another. Do you think it is feasible and relatively easy to implement.
I don’t think HA is suited for modifying the data. Maybe it could be used to suggest localized names for plants, but all the other facts would be quite ugly to try modify in HA.
In a more general topic, I think that modification to the details should be moderated somehow. So 3. parties should be allowed to create “pull requests” or “suggestions”, and some moderators should be used to approve or decline changes.
And also, you are hopefully aware that many of the plant images are water marked?
Finally, I downloaded a free, publicly licensend image to use as a temporary icon for the integration:
Please feel free to replace it with a better logo as soon as you have one.