How to define a service for a Modbus integration

Hi everyone,

I want to set the temperature of my Heating Boiler via Modbus TCP. I successfully read a couple of values via Modbus TCP from this boiler, but I have serious trouble understanding how to write variable to the boiler.

I want do do this, via PyScript (which also works already) because I think python is way easier then these pesky yaml files.
So from what I gather, I just need to define a Modbus service, which I then can call from pyscript. But I cannot figure the following to things out:

  • How the hell is it possible to define a standalone service? I tried the following, but it just gives an error that there is no integration called service
automation: !include automations.yaml
service: modbus.write_register
data:
  address: 2305
  unit: 1
  hub: SolvisRemote
  value: 50
  • And second, how can I tell the service that it shall have the temperature as an argument (which I set over pyscript)?

Sorry if this is a stupid question, but I really have problems understanding the yaml files correctly. As far as I understand, services are always part of an automation with trigger etc. but, that makes no sense to me…

Best,
Phil

1 Like

Okay, I figured it out. The thing I did not understand was the following: The service doesn’t need to be defined. You can call the service for example via a button card in lovelace.

For my two questions, this means that I can directly call the Modbus TCP write_register service. How to do this from PyScript is actually well documented, under “How to call services”.

The call from my question post above would therefore become:

modbus.write_register(hub='SolvisRemote', address=2305, unit=1, value=50)

(I should say that I have not yet tested this call…)

1 Like