Use of parameters in framework

Python and python framework

Moderator: leecollings

Post Reply
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

Use of parameters in framework

Post by JanJaap »

Hi,

I'm struggling a bit with the Parameters as exposed by the plugin framework. According to documentation, you have a standard set (like address, port, user/pwd etc) plus 6 user defined (mode1..mode6). However, when you make something completely user defined, it is nicely displayed in the HW page, but cannot be accessed from the code. For example, adding this to the plugin definition:

Code: Select all

        <param field="Scene1" label="Temp Away " width="50px" required="true" default="17.0" >
        <description><br/>==== Scene configuration ====</description>
        </param>
        <param field="Scene2" label="Temp Sleep " width="50px" required="true" default="18.0" />
        <param field="Scene3" label="Temp Home " width="50px" required="true" default="19.5" />
        <param field="Scene4" label="Temp Comfort " width="50px" required="true" default="20.0" />
Will generated this view:
Domoticz parameters.PNG
Domoticz parameters.PNG (5.07 KiB) Viewed 281 times
But leads to these errors when trying to access them in the code:

Code: Select all

2023-01-02 22:00:46.941 Error: Toon: if strCurrentTemp == Parameters["Scene1"]:
2023-01-02 22:00:46.941 Error: Toon: KeyError: 'Scene1'
So, long story short: would it be possible to use any user-defined parameter? It would be great to get rid of this 6 modes limitation......
In practice, a lot of plugins already have 2 Parameters:
- a refersh rate
- a debug logging selector
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Use of parameters in framework

Post by waltervl »

I think this question has been asked before and the answer was (if I remember correctly) that it needs a complex change. Perhaps check GitHub issues on this topic.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FlyingDomotic
Posts: 358
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Use of parameters in framework

Post by FlyingDomotic »

This works well naming user parameters "Mode1" to "Mode6". Here's an example:

Code: Select all

<plugin key="MqttMapper" name="MQTT mapper with LAN interface" author="Flying Domotic" version="1.0.4">
    <description>
      MQTT mapper plug-in<br/><br/>
      Maps MQTT topics to Domoticz devices<br/>
    </description>
    <params>
        <param field="Address" label="MQTT Server address" width="300px" required="true" default="127.0.0.1"/>
        <param field="Port" label="Port" width="300px" required="true" default="1883"/>
        <param field="Username" label="Username" width="300px"/>
        <param field="Password" label="Password" width="300px" password="true"/>
        <param field="Mode1" label="JSON mapping file to use" width="300px" required="true" default="MqttMapper.json"/>
        <param field="Mode6" label="Debug" width="100px">
            <options>
                <option label="Extra verbose" value="Verbose+"/>
                <option label="Verbose" value="Verbose"/>
                <option label="Normal" value="Debug"/>
                <option label="None" value="Normal" default="true"/>
            </options>
        </param>
    </params>
</plugin>
Values are read back using

Code: Select all

Parameters["Mode1"]
to

Code: Select all

Parameters["Mode6"]
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests