Nythbran23
(Nythbran23)
January 30, 2023, 12:42pm
1
Some help here please from anyone in the know:
I need to read the value of two Modbus holding registers in HEX and combine them before converting the combined total to Base 10
Example:
Address 8 Bytes 1 & 0 are 1BB3
Address 9 Bytes 3 & 2 are 0002
Combine the two to get 00021BB3
Convert to Base 10 to give 138663
Issues then -
How do I read them and store them as HEX? I cannot seem to find a structure format that will do that…
How do I combine them to a new value that can then be read and converted?
I am extracting the data in Int format fine using this:
- name: TOTAL_POWER_1
unique_id: CB_8
scan_interval: 10
address: 8
slave: 1
input_type: holding
unit_of_measurement: kWh
device_class: power
state_class: measurement
data_type: uint16
- name: TOTAL_POWER_2
unique_id: CB_9
scan_interval: 10
address: 9
slave: 1
input_type: holding
unit_of_measurement: kWh
device_class: power
state_class: measurement
data_type: uint16
I have tried custom structures and none seem to read it as HEX.
Any pointers please???
nikito7
(nikito7)
January 31, 2023, 2:10am
2
- name: TOTAL_POWER
unique_id: CB89
scan_interval: 10
address: 8
slave: 1
count: 2
data_type: uint32
swap: word_byte
input_type: holding
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
Nythbran23
(Nythbran23)
January 31, 2023, 5:00am
3
Thank you Nikito7
What that returns in the entity is two decimal values:
e.g. I get: 8935,2
Hex behind it is 22E7 0002
That needs to be combined in hex as a single word 000222E7
Converted to DEC this is then 140007 which is the correct reading I need to show on the entity.
nikito7
(nikito7)
January 31, 2023, 6:31pm
4
- name: TOTAL_POWER
unique_id: CB89
scan_interval: 10
address: 8
slave: 1
count: 2
data_type: uint32
swap: word ### this
input_type: holding
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
Nythbran23
(Nythbran23)
February 1, 2023, 3:57am
5
That just returns 2 in the entity
nikito7
(nikito7)
February 1, 2023, 4:58am
6
Change address to 7 or 9.
What you say above is word swap
AABB CCDD > CCDD AABB
byte swap
AABB CCDD > BBAA DDCC
word byte swap
AABB CCDD > DDCC BBAA
1 Like
Nythbran23
(Nythbran23)
February 1, 2023, 5:32am
7
Ok - we are good with this:
- name: TOTAL_POWER_1
unique_id: CB89
scan_interval: 10
address: 8
slave: 1
input_type: holding
unit_of_measurement: kWh
data_type: uint32
swap: word
count: 2
device_class: energy
state_class: total_increasing
Thank you very much!
1 Like
mr-gosh
(Mr Gosh)
December 4, 2024, 1:18pm
8
does this really work?
i get an config-check error:
count
illegal with data_type: uint32
mr-gosh
(Mr Gosh)
December 5, 2024, 9:33am
10
did that - as mentioned is this not necessary for uint and int - it is till not working for me - but thats possibly another problem