目的是自动/定期地生成一个XML文件,其中包含从Domoticz的数据中选择的动态值,就像Python-script中其他地方所提供的那样。生成的XML文件如下所示。
<response>
<value1>0.0</value1>
<value2>10.0</value2>
<value3>10.0</value3>
<value4>0.0</value4>
<value5>0.00</value5>
<time_stamp>20161215 20:44</time_stamp>
</response>要使这种XML-文件成为Python中的起点,可以使用字典,因为从字典中可以很容易地通过命令弓形文件生成XML文件。
然后,问题:如何编写一个字典,该字典参数化地包含来自Domoticz的所选动态值,并且可以通过命令库读取?
在我看来,这意味着:
正确/可行的方法?任何已知/可用的Python脚本是否实现了作业/序列?
发布于 2017-01-20 16:52:13
一些与Python字典相关的进一步搜索提供了足够的提示来生成脚本,并将其作为kWh-米类型1ZN 238-1ZN读入脚本的扩展。该脚本提供了到字典的动态链接。
这证明了第一个问题中提到的概念是正确的。
# --------------------------------------------------
# Make XML-file for DDS238-1ZN Read-out
# --------------------------------------------------
# Take care of extra dependencies
import dicttoxml
# Create the default dictionary
DDS238_dict = {'gauge_power': 1.2, 'gauge_temp': 20.4, 'gauge_vpv': 150, 'gauge_iac': 1.5, 'energy_today': 2.5, 'energy_total': 45.00, 'time_stamp': 0}
print(DDS238_dict)
# Link the directory to dynamic values in the Python-script (or fill-in placeholder values)
DDS238_dict['gauge_power'] = ActivPower
DDS238_dict['gauge_temp'] = 20.1
DDS238_dict['gauge_vpv'] = VOLTAGE
DDS238_dict['gauge_iac'] = CURRENT
DDS238_dict['energy_today'] = Wh_today
DDS238_dict['energy_total'] = Wh_life
DDS238_dict['time_stamp'] = now
print(DDS238_dict)
# Convert dictionary to XML-file
DDS238_xml = dicttoxml.dicttoxml(DDS238_dict)
print(DDS238_xml)显然,打印行是可选的(用于测试)。
-)很容易,如果你知道.
https://stackoverflow.com/questions/41752420
复制相似问题