『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 1260|回复: 2

[技术探讨] 请帮修改下培正配置文件新的MQTT格式

[复制链接]

8

主题

220

帖子

1666

积分

金牌会员

Rank: 6Rank: 6

积分
1666
金钱
1446
HASS币
0
发表于 2023-2-20 22:46:23 | 显示全部楼层 |阅读模式
############


mqtt:


#电压传感器
    sensor:
      - name: "jiadianya"
        state_topic: "tele/sonoff/SENSOR"
        qos: 1
        unit_of_measurement: "V"
        value_template: "{{ value_json['ENERGY'].Voltage }}"
     
    #电流传感器
      - name: "jiadianliu"
        state_topic: "tele/sonoff/SENSOR"
        qos: 1
        unit_of_measurement: "A"
        value_template: "{{ value_json['ENERGY'].Current }}"
     
    #功率传感器
      - name: "jiagonglv"
        state_topic: "tele/sonoff/SENSOR"
        qos: 1
        unit_of_measurement: "W"
        value_template: "{{ value_json['ENERGY'].Power }}"
     
    #功率因数传感器
      - name: "jiagonglvyinshu"
        state_topic: "tele/sonoff/SENSOR"
        qos: 1
        unit_of_measurement: "cosΦ"
        value_template: "{{ value_json['ENERGY'].Factor }}"
     
    #今天用电量
      - name: "jiajinri_dianliang"
        state_topic: "tele/sonoff/SENSOR"
        qos: 1
        unit_of_measurement: "kWh"
        value_template: "{{ value_json['ENERGY'].Today }}"
        
   #昨天用电量
      - name: "jiazuori_dianliang"
        state_topic: "tele/sonoff/SENSOR"
        qos: 1
        unit_of_measurement: "kWh"
        value_template: "{{ value_json['ENERGY'].Yesterday }}"
      
   #总用电量
      - name: "jiaelectric"
        state_topic: "tele/sonoff/SENSOR"
        qos: 1
        unit_of_measurement: "kWh"
        value_template: "{{ value_json['ENERGY'].Total }}"

#今日电费
- platform: template
  sensors:
    jiajinri_dianfei:
      value_template: >
        {% if now().month in [1,3,5,7,8,10,12] %}
        {% set date = (31 - now().day) %}
        {% elif now().month in [4,6,9,11] %}
        {% set date = (30 - now().day) %}
        {% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
        {% set date = (28 - now().day) %}
        {% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
        {% set date = (29 - now().day) %}
        {% endif %}
        {% if (date != 0 and (states("sensor.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.jiaelectric") | int > 350) %}
        {{(states("sensor.jiajinri_dianliang") | float * 0.9629) | round(2)}}
        {% elif (date != 0 and (states("sensor.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 200) or (date == 0 and states("sensor.jiaelectric") | int > 180) %}
        {{(states("sensor.jiajinri_dianliang") | float * 0.7129) | round(2)}}
        {% else %}
        {{(states("sensor.jiajinri_dianliang") | float * 0.6629) | round(2)}}
        {% endif %}
      unit_of_measurement: "RMB"


#昨日电费
- platform: template
  sensors:
    jiazuori_dianfei:
      value_template: >
        {% if now().month in [1,3,5,7,8,10,12] %}
        {% set date = (31 - now().day) %}
        {% elif now().month in [4,6,9,11] %}
        {% set date = (30 - now().day) %}
        {% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
        {% set date = (28 - now().day) %}
        {% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
        {% set date = (29 - now().day) %}
        {% endif %}
        {% if (date != 0 and (states("sensor.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.jiaelectric") | int > 350) %}
        {{(states("sensor.jiazuori_dianliang") | float * 0.9629) | round(2)}}
        {% elif (date != 0 and (states("sensor.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 200) or (date == 0 and states("sensor.jiaelectric") | int > 180) %}
        {{(states("sensor.jiazuori_dianliang") | float * 0.7129) | round(2)}}
        {% else %}
        {{(states("sensor.jiazuori_dianliang") | float * 0.6629) | round(2)}}
        {% endif %}
      unit_of_measurement: "RMB"


#总电费
- platform: template
  sensors:
    jiazongdianfei:
      value_template: >
        {% if now().month in [1,3,5,7,8,10,12] %}
        {% set date = (31 - now().day) %}
        {% elif now().month in [4,6,9,11] %}
        {% set date = (30 - now().day) %}
        {% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
        {% set date = (28 - now().day) %}
        {% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
        {% set date = (29 - now().day) %}
        {% endif %}
        {% if (date != 0 and (states("sensor.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.jiaelectric") | int > 350) %}
        {{(states("sensor.jiaelectric") | float * 0.9629) | round(2)}}
        {% elif (date != 0 and (states("sensor.jiaelectric") | float - states("sensor.jiajinri_dianliang") | float + (states("sensor.jiazuori_dianliang") | float * (date + 1))) | int > 200) or (date == 0 and states("sensor.jiaelectric") | int > 180) %}
        {{(states("sensor.jiaelectric") | float * 0.7129) | round(2)}}
        {% else %}
        {{(states("sensor.jiaelectric") | float * 0.6629) | round(2)}}
        {% endif %}
      unit_of_measurement: "RMB"
#计量清零
automation:
  - id: 'monitor_clear'
    alias: monitor_clear
    initial_state: true
    hide_entity: false
    trigger:
      - platform: template
        value_template: '{{ states("sensor.jiajinri_dianliang") | round(3) == 0.000 }}'
    condition:
      - condition: template
        value_template: '{{ (now().strftime("%d") | int) == 1 }}'
    action:
      - service: mqtt.publish
        data:
          topic: 'cmnd/sonoff/EnergyReset2'
          payload: '0'
      - service: mqtt.publish
        data:
          topic: 'cmnd/sonoff/EnergyReset3'
          payload: '0'
  
#计量清零
# automation:
#   - id: 'monitor_clear'
#     alias: monitor_clear
#     initial_state: true
#     hide_entity: false
#     trigger:
# # - platform: time
# # at: '00:00:00'
#       - platform: template
#         value_template: '{{ states("sensor.jiajinri_dianliang") | round(3) == 0.000 }}'
#     condition:
#       - condition: template
#         value_template: '{{ (now().strftime("%d") | int) == 1 }}'
#     action:
#       - service: mqtt.publish
#         data:
#         topic: 'cmnd/sonoff/EnergyReset2'
#         payload: '0'
#       - service: mqtt.publish
#         data:
#         topic: 'cmnd/sonoff/EnergyReset3'
#         payload: '0'

# group:
#   electric:
#   name: 总电量
#   view: no
#   entities:
#     - sensor.jiadianya
#     - sensor.jiadianliu
#     - sensor.jiagonglv
#     - sensor.jiagonglvyinshu
#     - sensor.jiajinri_dianliang
#     - sensor.jiajinri_dianfei
#     - sensor.jiazuori_dianliang
#     - sensor.jiazuori_dianfei
#     - sensor.jiaelectric
#     - sensor.jiazongdianfei
#     - automation.monitor_clear

homeassistant:
  customize:
    sensor.jiadianya:
      friendly_name: 电压
      icon: mdi:flash
      # homebridge_name: 机柜电压
      # homebridge_hidden: false

    sensor.jiadianliu:
      friendly_name: 电流
      icon: mdi:flash-auto
      # homebridge_name: 机柜电流
      # homebridge_hidden: false

    sensor.jiagonglv:
      friendly_name: 功率
      icon: mdi:wikipedia
      # homebridge_name: 功率
      # homebridge_hidden: false

    sensor.jiagonglvyinshu:
      friendly_name: 功率因数
      icon: mdi:flash-red-eye
      # homebridge_name: 功率因数
      # homebridge_hidden: false

    sensor.jiajinri_dianliang:
      friendly_name: 今日电量
      icon: mdi:flash
      # homebridge_name: 今日电量
      # homebridge_hidden: false

    sensor.jiajinri_dianfei:
      friendly_name: 今日电费
      icon: mdi:currency-cny
# homebridge_name: 今日电费
# homebridge_hidden: false

    sensor.jiazuori_dianliang:
      friendly_name: 昨日电量
      icon: mdi:flash
# homebridge_name: 昨日电量
# homebridge_hidden: false

    sensor.jiazuori_dianfei:
      friendly_name: 昨日电费
      icon: mdi:currency-cny
# homebridge_name: 昨日电费
# homebridge_hidden: false

    sensor.jiaelectric:
      friendly_name: 总电量
      icon: mdi:flash
      # homebridge_name: 总电量
      # homebridge_hidden: false

    sensor.jiazongdianfei:
      friendly_name: 总电费
      icon: mdi:currency-cny
# homebridge_name: 总电费
# homebridge_hidden: false

    automation.monitor_clear:
      friendly_name: 计量清零
      # homebridge_name: 计量清零
      # homebridge_hidden: false

# group.electric:
# homebridge_hidden: false

海鲜市场:jasona3
回复

使用道具 举报

8

主题

220

帖子

1666

积分

金牌会员

Rank: 6Rank: 6

积分
1666
金钱
1446
HASS币
0
 楼主| 发表于 2023-2-20 22:47:50 | 显示全部楼层
Error loading /config/configuration.yaml: while parsing a block mapping
in "/config/packages/jiapower.yaml", line 3, column 1
expected <block end>, but found '-'
in "/config/packages/jiapower.yaml", line 56, column 1

报以上错误
海鲜市场:jasona3
回复

使用道具 举报

8

主题

69

帖子

553

积分

高级会员

Rank: 4

积分
553
金钱
484
HASS币
0
发表于 2023-2-21 10:12:20 | 显示全部楼层
我过年的时候更新了一下系统,mqtt也开始报错了,应该是引入格式有调整,因为我之前是拆分文件的写法,现在只能加到configuration里
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-28 06:52 , Processed in 0.175954 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表