I am implementing a Modbus Connection with my Siemens LOGO within HomeAssistant.
Now, I am on a point, where I want to read some variables the LOGO is using internally to do the automation - for example, the time from a specific block which does trigger a light to be turned on or off.
LOGO does send this information in Decimal (time sunrise, time sunset)
It would be really great, if it would be possible to specify a “value format” within the Modbus Plattform, rather than creating an additional template Sensor for converting the Decimal value into a string like (07:07) - and then, maybe create a timestamp from this.
I could imagine something like
value_format: {{ your code to format the raw value }}
the “state” should be defined within the sensors configuration directly, rather than creating a sensor - and on top of that another templated sensor to transform the output.
In the past weeks I learned the following: while it might be very convenient to define individual sensors (or even have them auto-generated) by the Modbus integration, working with them individually (e.g. reading/writing) becomes inefficient very quickly and this approach practically doesn’t scale. It is only viable for very small configurations like yours - just 2 sensors. As soon as you have 10 or more registers, and/or you would like to scan them more frequently than every 10 seconds, doing this sequentially (e.g. one by one) quickly saturates the link.
A better solution is to always read all of them in a single command (provided they are laid out sequentially which is usually the case for most devices). The current integration has just the right tools for that with its structure functionality. The following example reads all 12 words with a single command and tells the integration how to parse them (at Modbus level):
From here on, one needs to split this into an array and format individual (template) sensors to one’s liking. E.g. template sensors would be required anyway in this case.