NWT.Stuff

I am currently using voice control on ALEXA and Google Assistant for
- Switching Lights On and Off (using RPI-GPIO & Relay modules)
- Announcing Current Temperature values (using SQL Query to database)


The platform I am using is called Home Assistant which sits on a Raspberry Pi in my case. It is possible to make certain functionality available in ALEXA or Google Assistant (This can be done long hand manually or pay a $5 monthly subscription to do it quickly).


I recently noticed that there is a Modbus Integration https://www.home-assistant.io/integrations/modbus/ so I thought I would test it with Open PLC.


I decided to test the simplest functions with Output Coils and Discrete Input Registers.  The Software refers to entities / functionality as follows:-


Binary Sensor

Reads discrete inputs and state of output coils (Modbus Functions FC1 & FC2) https://www.home-assistant.io/integrations/binary_sensor.modbus/

Switch
Write an Output Coil (Modbus Function FC5) https://www.home-assistant.io/integrations/switch.modbus/

If you look at the video in the link you will see that these functions work well.
- ix00 = %ix0.0 = PLC Heartbeat
- qx10 = %qx1.0 = Test Output Coil

https://youtu.be/HqmrSO1tRRc


Whilst this is only proof of concept it seems this Software provides interesting functionality for OpenPLC enthusiasts/users:
- Functioning Modbus Master
- Animation & Control using Web Browser Interface, Android & iOS apps.
- Historical Logging of states and values
- Gateway to both Amazon ALEXA and Google Assistant


My next steps will be test briefly
- Holding Registers (Read & Write Analogue Values)
- Which functions can be extended to Voice Control & How.

Reply 1 0
NWT.Stuff

Moving on from the above post.


Switch https://www.home-assistant.io/integrations/switch.modbus
The switch integration also includes the functionality on the actuation of a switch to write an analogue value for the on state and off state. 


Setting up the Home Assistant for the first time takes some getting used to but once implemented the code is quite simple.


In this example the Modbus Slave is defined as follows
2021-02-23 Slave.jpg 


The Modbus Switch is configured like this
2021-02-23 Switch.jpg 


Output Coil – Address is 8 = %qx1.0 in OpenPLC Mapping
Register Switch
 -Switch ON: value 100 is written to register 1024 (OpenPLC %MW0)
 -Switch OFF: value 50 is written


https://youtu.be/8ov4M8DOh2c


Next Test – Reading & Writing Analogue Values (Open PLC Registers)

 

Reply 0 0
NWT.Stuff
Reading & Writing Analogue Values (Open PLC Holding Registers)

We can Read Holding registers using the Home Assistant platform Modbus Sensors

Sensor https://www.home-assistant.io/integrations/sensor.modbus/

The Modbus Sensor is configured as follows
2021-02-23 Sensor.jpg    

In this example we are monitoring address 1024 (Open PLC %MW0) & 1026 (Open PLC %MW2).  We have also defined a “measurement unit” as seconds.  This is only relevant in the user interface.

We can Write Holding registers using a combination
1-Home Assistant Integration Input Number /https://www.home-assistant.io/integrations/input_number
2-Home Assistant Modbus Service write_register https://www.home-assistant.io/integrations/modbus/


The Input Number Object is configured as follows
2021-02-23 InputNumber.jpg 

There are two options that I am aware of; a slider arrangement and an input number box. In the above example we have defined one of each.  It is also possible to define initial values, min, and max. The step is 1 in this case as we want to deal with Integers. The “scan_interval” will be the frequency at which the PLC Register will be interrogated and refreshed; which in this example has been set to 1 second.

When the Input Number is changed we want to write the new value to the Open PLC register.  This is achieved by using the following code.
2021-02-23 Automation.jpg 

The “trigger” for the value to be updated is the “input_number” object.  This will then execute the “write_register” service which will update the given “address” with the “value” assigned in the “input_number” object.

Simulation/Working Example
https://youtu.be/XFav08IE_-g


Whilst I have only tested with 16 bit registers (%MW) the documentation includes instructions on how to use 32 bit (%MD) and 64bit (%ML) registers.  I have not tested these yet although I may have an interest at a later stage to convert a time input into “seconds since midnight” to a double 32 bit word.


OK So I’m happy we can do just about everything we will need to do to control and animate the PLC.

So the next step is “What functionality can we achieve with Voice Control (Amazon Alexa & Google Assistant)?"

 


Reply 0 0
NWT.Stuff

Amazon ALEXA & Google Home Assistant

 

The Home Assistant does have instructions for Integration with

ALEXA https://www.home-assistant.io/integrations/alexa/

Google Assistant https://www.home-assistant.io/integrations/google_assistant/

 

The quickest way to set up and test is using the “Nabu Casa” subscription (which has a free month trial) https://www.home-assistant.io/cloud/

 

What I wanted to see is which of the Home Assistant/Open PLC objects would become available seamlessly (without the need to write additional code/script).  Unfortunately the list is rather short !! It Seems that the only object that is available for touch and voice control is the “Binary Switch” e.g. writing a %qx coil. See below
GoogleAlexa.jpg 

In order to implement 

- Read Binary Sensors (e.g. Input & output states) 

- Read & Write Registers

Additional scripts would have to be created in the Home Assistant Server.

 

I am confident that it will be possible to implement the Read Functions as I have already written and implemented these sort of scripts for reading database values and passing them on to ALEXA & Google Assistant.

 

I haven’t had the need to Write Values yet.  I am sure that would be achievable but much more complicated. I would like at some stage to implement a voice control boost function (1 hour, 2 hour etc.) for my hot water tanks but it is not a priority for now.

 

So my journey ends here for now.  It’s good to write down what I have done for reference.  If anyone has any comments, suggestions, alternative approaches I will welcome the feedback.

 

Kevin

P.S. attached Home Assistant Configuration File (configuration.yaml - plain text)

Reply 0 0
thiagoralves
This is really nice! I've heard of Home Assistant before, but never really tried it myself. With this integration it is now even easier to use OpenPLC on home automation projects. Well done Kevin, thanks for the contribution!!
Reply 1 0
NWT.Stuff
Hi Thiago, No worries, enjoyable work 🙂

For completeness here are screen shots of the User Interface on several platforms.  As you state the real advantage is integrating Open PLC Control seamlessly with other Home Automation (e.g. lights, rf sensors, garage door, TV's and other smart stuff etc. etc.)
HA-UI-Android-iOS.jpg 
HA-UI-PC.jpg 
Reply 0 0
self
Thank you for the write up, exactly what I was looking for! Will give it a try.  👾
Reply 0 0
Reply