help with panasonic cloud

Python and python framework

Moderator: leecollings

User avatar
FireWizard
Posts: 1905
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: help with panasonic cloud

Post by FireWizard »

Hi,

@Gianni
For the request maybe every 10 min?
Please find below a bash script that runs every minute. I suggest during testing to use a shorter period than 10 minutes.
Otherwise you have to wait so long. Unless the Panasonic Cloud service does not permit a call every minute.

The sleep command is now 57 seconds as the time it needs for publishing the MQTT message is about 3 seconds.
But you can check that and play with the value. Later on you can change that to 597 (10 minutes).

You can also add your second MQTT message, e.g for the bedroom. E.g. 10 seconds after the living.

If this bash script runs fine, you will see a new MQTT publication every minute.

I called the script "panasonic2mqtt.sh" and you have to make it eXecutable. (chmod +x panasonic2mqtt.sh)

Code: Select all

#!/bin/bash
# Script to push panasonic cloud to mqtt
# Uses mosquitto_pub

while :; do
  python3 pcomfortcloud.py login pasword get 1 | mosquitto_pub --url mqtt://127.0.0.1/panasonic/living -s
  sleep 57
done
The next step is Node Red.

I assume you have also installed Node Red on the same hardware as Mosquitto, Domoticz and your pcomfortcloud.py script.
If your browser is also installed on the same hardware use IP address 127.0.0.1 or otherwise the IP address of the device, which has Node Red installed.

If so open a browser and go to http://127.0.0.1:1880 and the Node Red workbench will open

In the "Hamburger" menu at the top right, go to "Import" and paste the following flow:

Code: Select all

[{"id":"5bae5c9d.cc469c","type":"tab","label":"Pansonic Cloud","disabled":false,"info":""},{"id":"895546b7.2d10c","type":"mqtt in","z":"5bae5c9d.cc469c","name":"MQTT In","topic":"panasonic/living","qos":"2","datatype":"auto","broker":"c2d9657a.d81bf8","x":160,"y":320,"wires":[["d0c887a4.afd0e"]]},{"id":"d0c887a4.afd0e","type":"debug","z":"5bae5c9d.cc469c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":330,"y":320,"wires":[]},{"id":"c2d9657a.d81bf8","type":"mqtt-broker","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":15,"cleansession":true,"birthQos":"0","willQos":"0"}]
It will show the following:
Screenshot_MQTT-debug.png
Screenshot_MQTT-debug.png (5.95 KiB) Viewed 1306 times
Go to the debug pane (the bug symbol just under the "Hamburger" menu.

If both the bash script and the Node Red flow are correctly installed, you will see approx. every minute the result in the debug pane.

Can you publish the content of what you see. A screenshot would be fine.

Regards
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

hello FireWizard

did everything like you say but no output on the debug window
add the bash into the same folder as the python script
Chmod the bash
chmod.JPG
chmod.JPG (47.66 KiB) Viewed 1298 times
copy the code into node red.
node.JPG
node.JPG (71.16 KiB) Viewed 1298 times
The only thing i added was to start node red on boot,because now i have to start node red manual everytime
https://nodered.org/docs/faq/starting-node-red-on-boot

greets gianni
User avatar
FireWizard
Posts: 1905
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: help with panasonic cloud

Post by FireWizard »

HI,

@Gianni,

What if you try with the second terminal. as we did befor.
So open een 2nd terminal and issue the mosquitto_sub command.

What do you see?

Regards
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

if i run the sub on the second en the pub on the first like we did before it works.
If i run the sub on the second and wait for 1 min for the script it's not work.
if i run the sub on the second an ./panasonic2mqtt.sh then i get a output on the sub


edit

if i run the script ./panasonic2mqqt.sh then i get output on node red

Code: Select all

reading from device 'Living' (id)id                       : id parameters    temperatureInside    : 24    temperatureOutside   : 15    temperature          : 24.0    power                : On    mode                 : Auto    fanSpeed             : Auto    airSwingHorizontal   : Auto    airSwingVertical     : Auto    eco                  : Auto
grts gianni
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

i create a second bash script and a second flow.
If i run the first bash i got readings from the first device.
If i run the second bash i got readings from the second device.
I will add the 2 bash files to my startup so whenever my server restart the bash files rerun 2.

Grts GIanni
User avatar
FireWizard
Posts: 1905
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: help with panasonic cloud

Post by FireWizard »

Hello @Gianni,

You wrote:
if i run the sub on the second en the pub on the first like we did before it works.
This is what we could expect, as nothing has changed. So that's okay.
If i run the sub on the second and wait for 1 min for the script it's not work.
We should carefully look at the script.
if i run the sub on the second an ./panasonic2mqtt.sh then i get a output on the sub
That means that the bash script is more or less okay, but ik does not loop.
if i run the script ./panasonic2mqqt.sh then i get output on node red
That sounds good and we can continue to make a flow.
i create a second bash script and a second flow.
You can do that, but I recommend to put that command in the same bash script and e.g. sleep 10 between the two commands.
If we want to run it as a service later, we have to make only one service file.
If i run the first bash i got readings from the first device.
If i run the second bash i got readings from the second device.
That is correct and what we can expect.
I will add the 2 bash files to my startup so whenever my server restart the bash files rerun 2.
You can do that, if you don't want to run it as a service.

Bash file:
See: https://www.cyberciti.biz/faq/bash-while-loop/
In the chapter:
How do I use while as infinite loops?

Infinite for while can be created with empty expressions, such as:

#!/bin/bash
while :
do
echo "infinite loops [ hit CTRL+C to stop]"
done
In fact this what I wanted, however I saw that there was a semicolon after while.

So I suggest that you change the bash file to:

Code: Select all

#!/bin/bash
# Script to push panasonic cloud to mqtt
# Uses mosquitto_pub

while :
do
  python3 pcomfortcloud.py login pasword get 1 | mosquitto_pub --url mqtt://127.0.0.1/panasonic/living -s
  sleep 57
done
And try again. If it is working you should see every minute a message in Node Red.

If you want to combine both command in one bash file, you can do:

Code: Select all

#!/bin/bash
# Script to push panasonic cloud to mqtt
# Uses mosquitto_pub

while :
do
  python3 pcomfortcloud.py login pasword get 1 | mosquitto_pub --url mqtt://127.0.0.1/panasonic/living -s
  sleep 7
  < SECOND COMMAND TO INSERT HERE>
  sleep 47
done
In this case you should see 2 commands in Node-Red with 10 seconds difference.

Can you confirm if this works.
I will make a flow example.

Regards
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

hello again :-)

is used the script with the combine options.
Not running in node red.
I need to start it again like ./panasonic2mqqt.sh
when i quit it's stopt running in node red.
Then in ONLY see the first unit (livinig) and not the second (slaapkamer)
Just to be clear i only add the sh file in the same folder as the python script,add the line's in it and chmod the file.

mvg Gianni
User avatar
FireWizard
Posts: 1905
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: help with panasonic cloud

Post by FireWizard »

Hi @Gianni

You wrote:
Not running in node red.
AND
when i quit it's stopt running in node red.
You modified the script with a second command, isn't it?

Do you see anything in the debug node of Node Red. You should see only the first message.

I do not completely understand.

If you start it with ./panasonic2mqtt, does the script panasonic2mqtt.sh run in a loop or gives it an error message?
Do you have to stop it with CTRL-C?

If it runs do you see multiple messages in Node Red debug node.
Just to be clear i only add the sh file in the same folder as the python script,add the line's in it and chmod the file.
That is correct. Can you publish the file?

The fact that you see only the first message is because you did not subscribe to the second message.
To do so:

Double click the MQTT In node.
Change the topic panasonic/living to panasonic/# (This # is a "wildcard")
Press "Done" and press "Deploy"

You should see now both

Another question.

Can you test for me a command with -l at the end instead of -s.
This will give multiple messages, probably I hope.

Best regards
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

Hi @Gianni

You wrote:
Not running in node red.
AND
when i quit it's stopt running in node red.
You modified the script with a second command, isn't it?

Do you see anything in the debug node of Node Red. You should see only the first message.

I do not completely understand.
i read it again and it's a little bit confused.
i mean it not run by itself in need to start it manualy

If you start it with ./panasonic2mqtt, does the script panasonic2mqtt.sh run in a loop or gives it an error message?
Do you have to stop it with CTRL-C?
it's run like that and i need to stop it witch control c



The fact that you see only the first message is because you did not subscribe to the second message.
To do so:

Double click the MQTT In node.
Change the topic panasonic/living to panasonic/# (This # is a "wildcard")
Press "Done" and press "Deploy"

You should see now both
indeed got the 2 devices now
Another question.

Can you test for me a command with -l at the end instead of -s.
This will give multiple messages, probably I hope.
i got the 2 devices,but every command in another line.
see screenshot to clear out :-)
node4.JPG
node4.JPG (36.7 KiB) Viewed 1263 times
mvg Gianni
User avatar
FireWizard
Posts: 1905
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: help with panasonic cloud

Post by FireWizard »

Hi,

@Gianni

You wrote:
it's run like that and i need to stop it witch control c
That is normal and that is what I expected (hoped for).

If you stop this process, either by CTRL-C or if you close the terminal, the process will stop.

I will send you a service file, so that the script can be run as a service.

If everything is correct you will now see in the debug pane of Node Red about 11 messages for each topic (11 for Living and 11 for Bedroom)
Can you publish all messages
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

it's run like that and i need to stop it witch control c

That is normal and that is what I expected (hoped for).

If you stop this process, either by CTRL-C or if you close the terminal, the process will stop.

I will send you a service file, so that the script can be run as a service.
oef i was all the time thinking how would you run this file automatically from within the bash and not as a service or cron.

If everything is correct you will now see in the debug pane of Node Red about 11 messages for each topic (11 for Living and 11 for Bedroom)
Can you publish all messages
is sent in into a pb

grts gianni
User avatar
FireWizard
Posts: 1905
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: help with panasonic cloud

Post by FireWizard »

Hi, @Gianni

Can you try the following flow.

Replace the 2 nodes with this one:

Code: Select all

[{"id":"895546b7.2d10c","type":"mqtt in","z":"5bae5c9d.cc469c","name":"MQTT In","topic":"panasonic/#","qos":"2","datatype":"auto","broker":"c2d9657a.d81bf8","x":160,"y":320,"wires":[["ccb5a50f.4461e8"]]},{"id":"ccb5a50f.4461e8","type":"string","z":"5bae5c9d.cc469c","name":"Trim ","methods":[{"name":"strip","params":[{"type":"str","value":" "}]},{"name":"split","params":[{"type":"str","value":":"},{"type":"num","value":"2"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":330,"y":320,"wires":[["7f7c8cad.7614fc"]]},{"id":"7f7c8cad.7614fc","type":"function","z":"5bae5c9d.cc469c","name":"To Domoticz","func":"switch (msg.payload[0]) {\n\n    case \"temperatureInside\":\n    msg.payload = {\"command\":\"udevice\",\"idx\":8,\"nvalue\":0,\"svalue\":msg.payload[1]};\n    break;\n    \n    case \"temperatureOutside\":\n    msg.payload = {\"command\":\"udevice\",\"idx\":9,\"nvalue\":0,\"svalue\":msg.payload[1]};\n    break;  \n    \n    case \"temperature\":\n    msg.payload = {\"command\":\"udevice\",\"idx\":10,\"nvalue\":0,\"svalue\":msg.payload[1]};\n    break;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":320,"wires":[["9fb89083.61ba9"]]},{"id":"9fb89083.61ba9","type":"debug","z":"5bae5c9d.cc469c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":320,"wires":[]},{"id":"c2d9657a.d81bf8","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
If everything is allright you will see something like this:

Screenshot_Panasonic1.png
Screenshot_Panasonic1.png (10.13 KiB) Viewed 1254 times
If you run the script (with -l option) you should see something like:

Screenshot_Panasonic2.png
Screenshot_Panasonic2.png (8.12 KiB) Viewed 1254 times
You will see that 3 times.

Please confirm.

P.S. Service file will follow tomorrow

Regards
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

Can you try the following flow.

Replace the 2 nodes with this one:
i got a error in trim(unknow string)
node5.JPG
node5.JPG (24.43 KiB) Viewed 1254 times
P.S. Service file will follow tomorrow
NP thx you to take so much time to get this work :-)
User avatar
FireWizard
Posts: 1905
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: help with panasonic cloud

Post by FireWizard »

Hi @Gianni,

I should have told you that the string node is not a default node in Node Red.

In Node Red goto the "Hamburger" menu and select "Manage palette".
Go to the "Install" tab and search for: node-red-contrib-string

Install this module.

For your information a screenshot of the Inside/Outside temperature.

Screenshot_Panasonic3.png
Screenshot_Panasonic3.png (80.69 KiB) Viewed 1253 times
The rest will follow tomorrow.

Regards
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

great thx

will fix it and be ready for the rest .

grts gianni
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

so i did a little testing yesterday.
i create a dummy switch and add some temp devices's on .
Add my idx to the node red domoticz

Code: Select all

switch (msg.payload[0]) {

    case "temperatureInside":
    msg.payload = {"command":"udevice","idx":137,"nvalue":0,"svalue":msg.payload[1]};
    break;
    
    case "temperatureOutside":
    msg.payload = {"command":"udevice","idx":138,"nvalue":0,"svalue":msg.payload[1]};
    break;  
    
    case "temperature":
    msg.payload = {"command":"udevice","idx":139,"nvalue":0,"svalue":msg.payload[1]};
    break;
}

return msg;
but i got no value so i think i'm not ready to do it allone :lol: :lol: :lol:
dom1.JPG
dom1.JPG (27.39 KiB) Viewed 1218 times

another thing that i see in that my living and slaapkamer get the same idx in node red debug

Code: Select all

panasonic/living : msg.payload : Object
{ command: "udevice", idx: 139, nvalue: 0, svalue: "20.0" }


panasonic/slaapkamer : msg.payload : Object
{ command: "udevice", idx: 139, nvalue: 0, svalue: "22.0" }
grts Gianni
User avatar
FireWizard
Posts: 1905
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: help with panasonic cloud

Post by FireWizard »

Hello goodmorning.

@Gianni

You area little bit ahead of me. :D

The current script does not make a difference between the topics . So all values go to the same IDX

It has to be added, but therefore I would appreciate to see one or more screenshot from the debug node connected to the MQTT Out node.
I expect also some errors from a couple of non relevant messages such as:
reading from device 'Living' (********************************************************id**********************************)
id : ********************************************************id**********************************
parameters
but i got no value so i think i'm not ready to do it allone
We did not discuss, that you had to connect Domoticz to your MQTT server.
If not done,do as follows:

Open the Setup > Hardware tab
Add new hardware by:
-Give it a name, e.g Panasonic Cloud or whatever. Up to you.
- As type select MQTT Client Gateway with LAN interface
- Remote Address 127.0.0.1 (if Domoticz and Mosquitto runs on the same hardware)
- Port 1883
- No username and no password.

Regards
- Other setting are default.

In order to prepare the service file I have a question:

On what hardware is everything running and Domoticz version?
Is it using as init SysV or systemd?
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

Hello and goodmorning to you 2


You area little bit ahead of me. :D

The current script does not make a difference between the topics . So all values go to the same IDX

It has to be added, but therefore I would appreciate to see one or more screenshot from the debug node connected to the MQTT Out node.
I expect also some errors from a couple of non relevant messages such as:
i thought i will try it but no luck :-)


We did not discuss, that you had to connect Domoticz to your MQTT server.
If not done,do as follows:
this is already done in my initial setup the first time i installed domoticz.
I need to install the mqqt for my esp devices when i follow the online tutorial.

In order to prepare the service file I have a question:
On what hardware is everything running and Domoticz version?
Is it using as init SysV or systemd?
i have a hp dl360 rack server raid5.
50 gig ram cpu @2.10 GHz with 6 cores
running esxi on the host.
Domoticz is running on ubuntu server 20.04
vm got 1 cpu ,2 gig ram and a 60 gig hdd

Domoticz version is Version: 2020.1 (build 11981)

mvg Gianni
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: help with panasonic cloud

Post by Gianni »

slaapkamer.JPG
slaapkamer.JPG (72.47 KiB) Viewed 1210 times
living.JPG
living.JPG (74.59 KiB) Viewed 1210 times
User avatar
FireWizard
Posts: 1905
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: help with panasonic cloud

Post by FireWizard »

Hi,

@Gianni,

Thank you for the pictures, it is what I need.

Please find below a "service" file.

I suggest that you call the file: panasonic2mqtt.service.

Code: Select all

[Unit]
Description=panasonic2mqtt
After=network-online.target

[Service]
Type=simple
ExecStart=/home/gianni/panasonic/panasonic2mqtt.sh
Restart=always
RestartSec=1
StartLimitIntervalSec=0
User=root
Group=root

[Install]
WantedBy=multi-user.target
Steps to take:

1. Create file panasonic2mqtt with the contents, as above.
2. Check carefully the path and the user and group. I assume you run the script as root, but you can try to change it to gianni
3. Copy the file to /etc/systemd/system
4. Make it executable, chmod +x panasonic2mqtt.service
5. Stop the running process panasonic2mqtt.sh with CTRL-C
6. Start the service with: sudo systemctl start panasonic2.mqtt.service
7. Check for errors with: sudo systemctl status panasonic2.mqtt.service and check that the values are pushed to Mosquitto
8. If everything is okay stop the service with: sudo systemctl stop panasonic2.mqtt.service. Check with sudo systemctl status panasonic2.mqtt.service that it really has stopped.
9. Enable the service, so that it will run directly after reboot or startup: sudo systemctl enable panasonic2.mqtt.service
10 Start the service again or reboot to check that it runs.

Regards
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest