Help needed to config structure binary modbus sensor datatype


Can somebody help me with the following config problem?

I have a modbus sensor working.
No issue with that.
Now this sensor is reading an modbus input register type of my WAGO PLC.
I receive the result and it completely reflects the amounts I expect…
However I need to convert this in binary as the decimal result is a combination of bits.
One bit is representing an output of my PLC (for example a lamp or a motor of my ventilation etc)
Reading the modbus sensor manual I see the following :
Data_type : custom
Structure: python struct format string to unpack the value

So seen the above and to my understanding it should be possible to “EXTRACT” a bit out of the received decimal register.

For example the register is showing now 394 which is 110001010 in binary which tells me that the PLC has 4 outputs “on” as they are on 1 and 5 “off” as they are on 0.

The solution I am looking for is of the kind of “modbuskitchensensor = on if bit 5 of the received modbus register is 1”.

The solution could be perhaps be templating or the combination with data_type and structure.

In none of the possible solutions I have made any progress…

So who of the coding goeroes can help me? :slight_smile:

Happy newyear and already thanks in advance


Nobody :frowning:
Any hints :slight_smile:


Ever get anywhere on this? I’m trying to do something similar with my boiler to split out the status byte.


No I ended up writing a python script that is called each 10 seconds.
Not the best solution but a solution.
See this : Modbus sensor



what kind of WagoPLC are you using? if it’s programmable in CoDeSys 3 I would suggest having a look at this:

It’s a MQTT enabled home automation project. Instead of polling for updates using Modbus you can receive MQTT events instead. Much more flexible :wink: