Modbus tcp info on entities

Pretty much…I try to use HA as my monitoring device and program my PLC to do the nuts and bolts stuff. For devices which are not able to have their own program then HA takes on that role.
For your use then it’s up to you how you setup your system of course.

Good morning,
I’m back on the subject because I can’t understand how to visualize the status of an on / off button.
Every time I press the button the light turns on and for a moment the button is yellow but soon after Phrygian returns but the light stays on. If I press the button again the light is turned off and the yellow button returns to gray.
I use bistable relays and I get the relay status from a second contact that enters the plc from an input.
So if the input status is high the lamp is on and if it is low the lamp is off.
In HA I entered a register that at the push of a button writes the value on the Modbus to turn on the light.

    registers:
      - name: Test
        hub: maxi
        slave: 1
        register: 1
        command_on: 1
        command_off: 0

I then added a switch that reads the value of its input

   coils:
     - name: Test
       hub: maxi
       slave: 1
       coil: 1

So in HA I have a button and a switch and I see that those work correctly!
When I press the button, which writes in the modbus register, shortly after I see the switch turned on and permanent, if we repeat the button the switch goes off.

How can I create a code that shows the light status in one button?

Thanks, Alberto

I try to rephrase the question because I just can’t do what I would like … maybe impossible?
Then I have relays controlled via modbus.
The modbus command controls bistable relays.
The relays have 4 contacts
two contacts are used to switch on the lamp, the other two are used to know the status of the lamp ignition.
The lamp ignition status enters an input that reads the status.
If high the lamp is on if low is off.
In the home assistant I inserted a switch that turns on a lamp and a sensor that reads the status.
I would like the pressure of the switch in HA to illuminate the icon and remain so, but when I press the button the light turns on but the status of the icon after a short time goes off while the light is on.
While the icon of the state that controls the status remains on.
How can I do everything with a button?

Thanks, Alberto

@alverman Perhaps this image may help you see what I am trying to explain a little better?

From left to right:

Flag F8 is configured as my HA Modbus switch entity. I use it to toggle the state of my PLC Switch Device B013.

I can also toggle this locally via the digital input I006.

The output of the PLC Switch Device B013 turns the output high or low depending on its state.

I read that state via Flag F14 which is configured as my HA Modbus binary sensor entity.

I can also control field devices via Digital Output Q003.

Please let me know if that is any clearer?

Thanks Wellsy

I think, I say I think I understand what you mean.
If so, as I think I understand, but I use a step by step relay then the plc output does not remain high.
In fact modbus goes high with an impulse and the relay exchanges (on) then returns to zero, another impulse exchanges (off) and returns to zero.

Sorry but I see a flaw in my explanation…

The digital output is what would actually turn the light on or off in your setup (ie: your plc relay)
The Flag F14 which is configured as a binary sensor entity is giving you the on or off status of your light.

However I would always have a button (switch in HA) that turns on but the display would always be through another component (sensor in HA)
I would need the switch to do its duty but its icon would show the status of the sensor :wink: !!
I’ve been going around this thing for weeks and now I think it’s not possible with HA.
Too bad I’d miss only that to start replacing codesys with HA.
He has so many things that make me gorge but if I can’t do this for me it’s just, unfortunately, a waste of time.

Thanks anyway

The modbus implementation in HA is possibly not as ‘mature’ as other platforms such as MQTT say but I for one find it is reliable and I can live within its limitations.
HA has so many other benefits once you get it nutted out I would encourage you to try to live with some minor limitations.
I moved from a so called ‘professional’ SCADA product which had absolutely nothing on this fantastic product which by the way is still in beta state. Chin up keep plugging away!

PS: have you looked at node-red? It has some pretty nifty modbus Contrib’s which may be what you are looking for?

@alverman As an illustration here is a way I have learned to live with the limitations and at the end of the day (for me anyway) the solution seems to be more logical…?

In the case of my Grey Water Sump (my Control Panel).

The logic starts from the bottom working upwards to the pump icon:

  • I can set a limit on how many times I want the pump to run (the program resets it every 6 hours)
  • Then I can read the current runcount setpoint
  • If I wish and runcount trips I can reset it
  • Then I can see if other systems are not ready to receive grey water (inhibit on or off)
  • See if the runcount is tripped or not
  • HA Switch here Turn the system from Off to Auto NOTE: this is not a toggle switch. For process reasons I want the system to not restart if I lose power. It restarts in Off position.
  • HA binary sensor here Read that the system status is Auto or is Off (it is presently On so is Auto)
  • See the Level is above or below Low
  • See the Level is above or below High
  • See the pump is running or not
1 Like

Thanks Wellsy for your interest :grinning:
Actually I don’t want to abandon HA also because making small changes in codesys involves different problems.
While in HA it is simpler and more immediate.
Actually I also thought of node red, I installed it but at the moment it doesn’t work for me.
I’ll be in the tests because actually HA satisfies me 99%.
That little 1% is only given by my need to have a button that enables the icon based on a state.
I am confident: D

Thanks, Alberto

Cool…post your problems you are having (on a new post) with node-red and/or look up the videos on youtube which got me up and running easy enough. For my needs I have shut down node-red as I am looking more towards keeping everything running on HA alone.

But wouldn’t it be easier to modify entity button?
I ask !!
Where is the code of those components … I would like to put the nose :face_with_monocle:

You can look at modbus hub code here

Likewise modbus switch code here

I have solved here: https://community.home-assistant.io/t/entity-button-with-icon-state-on-value-of-sensor-on-off/121262/19

thank to finity !!

Hi, I am also struggling to get ModBus working in Home Assistant, most likely it is a silly mistake, but I would welcome some help. Here is the problem:

I purchased a USR-IO424T-EWR Modbus device. It has 4 x binary inputs, 4 x binary outputs, a PT100 temperature input and two 0-5 Volt analogue inputs. I am using it to monitor functions of a microwave Power Amplifier for the GB3JV Amateur Radio repeater www.gb3jv.co.uk

Using the USR App via the USR Cloud everything is working just fine. In Home Assistant I am seeing the Entities that I have configured, but they are not updating. I think my issues might be that I am mis-interpreting the correct registers and the difference in terminologies when interfacing to Home Assistant. This is my config.yaml in Home Assistant:


modbus:
  name: USR-NET-IO
  type: tcp
  host: 192.168.30.104
  port: 502

sensor:
  platform: modbus
  registers:
    - name: Temperature1
      hub: USR-NET-IO
      unit_of_measurement: °C
      register: 6980
    - name: VIN1
      hub: USR-NET-IO
      unit_of_measurement: V
      register: 6976

switch:
  platform: modbus
  coils:
    - name: DO4
      hub: USR-NET-IO
      coil: 6971

The picture shows the USR Application and the names, I am only using 3 of the inputs right now. The Voltage input represents the VSWR from the antenna.

I’ve also attached a Wireshark Capture. The Home Assistant server is on 192.168.0.24 and the Modbus Device on 192.168.30.104. The (working) Chinese cloud server is on 106.14.135.57. I can see Home Assistant appears to be querying the controller and the controller responding, but it looks like the wrong registers. In the screenshot of the trace you can see the Chinese server querying the device and getting the correct response, but the Home Assistant sever query is incorrect, really my question is how can I ensure that the Home Assistant server sends the same query to the Modbus Controller?

I would very much appreciate any help here.

I’m not sure you asking for the right coil/register position.
Download the tool below (it will only work for 10min unless you buy it, just close and open to reset, hit OK to go past the serial enter page)

Have a look at setup>“read/Write definitions” menu option to make sure you are querying the right location and getting the data you expect to see there.

www.modbustools.com/modbus_poll.html

Hi Chris, you were right, the Chinese tool had the registers labelled incorrectly, but the latest manual had the correct registers. I have a MAC, so I used another tool (£2.99) Called “ModBus Client” on the Mac App store to diagnose the issue and sorted it! Many thanks for the tip that sent me in the right direction.

Just the scale factor to sort now, but any Idea how I can convert Voltage into reverse power of an RF System? Like a custom scale.

1 Like

If anyone else is planning to use this device with Home Assistant I can honestly recommend it, it is a super little device especially now that I have sussed it out. Happy to share some config details if it interests people.

Hi Justin,
do you have the ability to do math’s on the 485 bridge?
I am yet to do maths in HA, however i believe that you will need to make a template or script to make new data, possibly very wrong however :rofl:

Chris, I’ll have to work this one out!

One measurement is for Standing Wave Ratio. I know on the probe that 5.0V = 1:1 SWR and that 0V = ∞ SWR. So how I convert a gauge to read SWR. As a work round I’ve called 5V = 50dB Return Loss and 0V = 0dB Return Loss, so the 3.5V reading I am getting is about 35dB Return Loss. Actually this agrees with the measured value.

In reality the voltage reading on the probe relates

to the reflected power level in Watts, so I need to perform a calculation that works out the SWR or return loss based on the known forward power level, in this case 20 Watts.

So I know 0V = 20W and 5V = 0W and I also know Pf is 20W, but how do I make a nice gauge that is calibrated and reads according to the formula? First World problems!