How to set value of ESPHome Entity?

I’m using an ESP32 to interface my security panel. In my ESPhome file I’ve set up a virtual zone and I’m trying to figure out how to set the value of the entity Home Assistant creates based on that virtual zone. I looked into automations, but I’m not seeing how I can use it to set the value of an entity, only devices.

Would someone be so kind as to point me in the right direction? 🙇‍♂️

It is usual to provide a copy of your yaml.

is there not a uniform way to set the status of entities?

The state of entities in esphome and home assistant should reflect each other, although quite how it all works depends on the type of entity. For example, a sensor can’t be set, it senses something and tells you what it is. It makes no sense to control it.

Anyway, as I said, it is usual to provide a copy of your yaml.

Sorry, I’m not where I can upload it at the moment, but I think we’re almost there. I get that the state of entities reflect each other, that’s why I’m trying to understand how to set the value of an entity in home assistant. For the moment, the fact that entity goes back to ESPhome is somewhat irrelevant, I don’t understand how I’m supposed to set the value of ANY entity from an HA automation. :rofl:

Same as you set any entity. Give me a concrete example. That is why I requested your yaml.

Same as you set any entity

Okay and how do you do that?? That’s what I keep asking for information on. You clearly know how to do this and I obviously don’t, I fail to see why you need the yaml file to share this information but here it is. I’m trying to set the one with the id z9.

#for documentation see project at https://github.com/Dilbert66/esphome-dsckeybus

#you can enter a list of user codes mapped to their names for display in armed/disarmed event messages
globals: 
  - id: userCodes
    type: std::string
    restore_value: no
    initial_value: '"1:Matthew,2:Amy"' 
    
substitutions:
  # change the name to suit your needs. This is what esphome will use as the friendly name for your component.
  # also used as a prefix for all fields
  systemName: "dscalarm" 
  
  #Only comes into effect if a password prompt occurs when arming eg. night mode
  accessCode: !secret access_code 
  
  #used to select the default partition associated with the alarm panel messages
  defaultPartition: "1" 

  #zone expander addresses:
  # 9  - zones 9-16
  # 10 - zones 17-24
  # 11 - zones 25-32
  # 12 - zones 33-40 (for systems with 64 zone support)
  # 13 - zones 41-48 (for systems with 64 zone support)
  # 14 - zones 49-56 (for systems with 64 zone support)
  # 16 - zones 57-64 (for systems with 64 zone support)  
  expanderAddr1: "9" # 1st zone expander emulator address to use . Set to 0 to disable. 
  expanderAddr2: "0" # 2nd expander emulator address to use . Set to 0 to disable. 
  
  #ESP32 Pins
  dscClockPin: "22"
  dscReadPin: "21"
  dscWritePin: "18"

  #ESP8266 Pins
  #dscClockPin: "5"
  #dscReadPin: "4"
  #dscWritePin: "15"  
  
  maxZones: "16" # maximum amount of zones your system supports
  
esphome:
  name: $systemName
  platform: ESP32
  board: nodemcu-32s
  #platform: ESP8266
  #board: nodemcuv2

  includes:
    # subdirectory path where custom component *.h and *.cpp files are located
    - dscKeybusInterface/

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  ap:
    ssid: "$systemName"
    password: !secret wifi_password

logger:
  baud_rate: 115200
  level: DEBUG

##API communications - ensure the mqtt: section is commented if using this protocol
api:
   password: !secret api_password  
   #encryption:         
     #key: !secret encryption_key
     
##MQTT communications - ensure the api: section is commented if using this protocol
#mqtt:
  #broker: xxx.xxx.xxx.xxx #your mqtt broker address
  #port: 1883  
  #username: mqttuser #your mqtt user name
  #password: !secret mqtt_password #your mqtt user pass
  
ota:
   password: !secret ota_password
   safe_mode: True
   on_begin:
    then:
      - switch.turn_off: connection_status_switch   
   
status_led:
  pin:
    number: GPIO14
    inverted: no

#comment if using ESP8266 to conserve memory    
time:
 - platform: sntp
   id: sntp_time

custom_component:
 - id: dsckeybus
   lambda: |-
    auto DSCkeybus = new DSCkeybushome($dscClockPin,$dscReadPin,$dscWritePin);
    DSCkeybus->accessCode="$accessCode";
    DSCkeybus->maxZones=$maxZones;
    DSCkeybus->defaultPartition=$defaultPartition;
    DSCkeybus->debug=2; // 0 = off, 1 = minimal, 2 = all packets shown on console  3 =  + serial port debugging
    DSCkeybus->expanderAddr1=$expanderAddr1; //zone expander
    DSCkeybus->expanderAddr2=$expanderAddr2;
    DSCkeybus->onSystemStatusChange([&](std::string statusCode) {
       id(system_status).publish_state(statusCode);
    });
    
    // if you only have one partition, remove the case 2 and corresponding p2 sensor. You can also add more partitions if needed
    DSCkeybus->onPartitionStatusChange([&](std::string statusCode, int partition) {
       switch(partition) {
         case 1: id(p1).publish_state(statusCode); break;
      } 
    });
    
    DSCkeybus->onPartitionMsgChange([&](std::string msg,uint8_t partition) {
       switch(partition) {
         case 1: id(m1).publish_state(msg); break;
      } // if you only have one partition, remove the case 2 statement  and corresponding p2 sensor. You can also add more partitions if needed
    });    

    DSCkeybus->onPanelStatusChange([&](panelStatus ps,bool open,int partition) {
      switch (partition) {
        case 0: // all partitions hardware statuses
          switch(ps) {
            case trStatus: id(tr).publish_state(open);break;
            case batStatus: id(bat).publish_state(open);break;
            case acStatus: id(ac).publish_state(open);break;
            case panicStatus: id(panic).publish_state(open);break;
            default: break;
          };break;  
        case 1: //partition 1 armed/ready
          switch(ps) {
            case rdyStatus: id(rdy).publish_state(open);break;
            case armStatus: id(arm).publish_state(open);break;
            default: break;
          };break;
        case 2: //partition 2 armed/ready
          switch(ps) {        
          };break;

      };
    });
    
    DSCkeybus->onZoneMsgStatus([&](std::string msg) {
            id(zone_status).publish_state(msg);
    });
    
    DSCkeybus->onLine1Display([&](std::string msg,int partition) {
        switch(partition) {
            case 1: id(line1).publish_state(msg);break;
        }
    });
    
    DSCkeybus->onLine2Display([&](std::string msg,int partition) {
        switch(partition) {    
           case 1: id(line2).publish_state(msg);break;
        }            
    });
    DSCkeybus->onEventInfo([&](std::string msg) {
            id(event).publish_state(msg);
    });  
    
    DSCkeybus->onBeeps([&](std::string beep,int partition) {
        switch(partition) {    
            case 1: id(beeps).publish_state(beep);break; 
        }
    });    
    
    DSCkeybus->onFireStatusChange([&](bool open,int partition) {
      switch (partition) {
          case 1: id(f1).publish_state(open); break;
      }
    }); 
    
    DSCkeybus->onTroubleMsgStatus([&](std::string msg) {
            id(tr_msg).publish_state(msg); //non partition specific trouble messages
    });
    
    DSCkeybus->onZoneStatusChange([&](uint8_t zone, bool open) {
      switch (zone) {
        case 1: id(z1).publish_state(open); break;
        case 2: id(z2).publish_state(open); break;
        case 3: id(z3).publish_state(open); break;
        case 4: id(z4).publish_state(open); break;
        case 5: id(z5).publish_state(open); break;
        case 6: id(z6).publish_state(open); break;
      } // add or delete any zone you need above. Add the coresponding sensor id in the binary_sensor section
    });
    
    DSCkeybus->onRelayChannelChange([&](uint8_t channel, bool state) {
      switch (channel) {
        case 1: id(r1).publish_state(state); break;
      }
    });
    
    return {DSCkeybus};
    
 
#ESP32 only .  Calls a public function within the custom component above. In this case syncs the time   
#interval:
#  - interval: 3600s
#    then:
#      - lambda: |-
#          static_cast< DSCkeybushome*> (id(dsckeybus).get_component(0))->set_panel_time();  

# add or remove any zone you need. Please ensure you also add/remove the corresonponding case statement above
# change the name to match your own zone configurations
# if you don't want to delete a zone, you can also comment out the name: field to hide it from home assistant
binary_sensor:
    #zone status open/close for each zone 
  - platform: template
    id: z1
    name: "Front Door(z1)"
    device_class: door
  - platform: template
    id: z2
    name: "Garage Door(z2)"
    device_class: door
  - platform: template
    id: z3
    name: "Living Room Windows(z3)"
    device_class: window
  - platform: template
    id: z4
    name: "Dining and Family Room Windows(z4)"
    device_class: window
  - platform: template
    id: z5
    name: "Master Bedroom Windows(z5)"
    device_class: window
  - platform: template
    id: z6
    name: "Motion Detector(z6)"
    device_class: motion
    
  - platform: template
    id: rdy
    name: "$systemName Partition 1 Ready"

  - platform: template
    id: arm
    name: "$systemName Partition 1 Armed"
    
  - platform: template
    id: rdy_2
    name: "$systemName Partition 2 Ready"

  - platform: template
    id: arm_2
    name: "$systemName Partition 2 Armed"    

    #panel trouble status on/off
  - platform: template
    id: tr
    name: "$systemName Trouble Status"
    device_class: problem
    
    #battery status ok/low
  - platform: template
    id: bat
    name: "$systemName Battery Status"
    device_class: problem

    #AC power status ok/no power
  - platform: template
    id: ac
    name: "$systemName AC Status"
    device_class: plug
    
    #panic alarm on/off
  - platform: template
    id: panic
    name: "$systemName Panic Status"
    device_class: safety
    
    #fire alarm on/off
#  - platform: template
#    id: f1
#    device_class: safety
#    name: "$systemName Fire partition 1 Status"
    
    #fire alarm on/off
  - platform: template
    id: f2
    device_class: safety
    name: "$systemName Fire partition 2 Status"    
    
#relay PGM channels. Will show the state of the activate relay channel on/off
#uncomment the name: field if you wish to see it in home assistant
  - platform: template
    id: r1
    name: "$systemName PGM 1"
  - platform: template
    id: r2
    name: "$systemName PGM 2"
  
#  - platform: custom
#    id: c1
#    device_class: door
#    on_press:       #pin high=off(closed), pin low=on(open)
#      - lambda: |-
#          dsc.setZoneFault(9,0);  #set zone 9 as open
#    on_release:
#      - lambda: |-
#          dsc.setZoneFault(9,1);  #set zone 9 as closed
  - platform: template
    id: z9
    device_class: door
    name: "Backdoor Open(z9)"
#set zone 9 as closed 
    on_press:       #pin high=on(closed), pin low=off(open)
      - lambda: |-
          dsc.setZoneFault(9,0);  
#set zone 9 as open   
    on_release:
      - lambda: |-
          dsc.setZoneFault(9,1);  
  - platform: gpio  
    pin: GPIO27
    id: f1
    device_class: smoke
    name: "Smoke Alarm Active(z10)"
#pin high=on(smoke detected), pin low=off(normal)
#set zone 10 as on    
    on_press:       
      - lambda: |-
          dsc.setZoneFault(10,0);
#set zone 10 as off    
    on_release:
      - lambda: |-
          dsc.setZoneFault(10,1);

              
  #- platform: template
  #  id: r3
  #  name: "$systemName PGM 3"
  #- platform: template
  #  id: r4
  #  name: "$systemName PGM 4"
  #- platform: template
  #  id: r5
  #  #name: "$systemName PGM 5"
  #- platform: template
  #  id: r6
  #  #name: "$systemName PGM 6"
  #- platform: template
  #  id: r7
  #  #name: "$systemName PGM 7"
  #- platform: template
  #  id: r8
  #  #name: "$systemName PGM 8"
  
    
# this sensor below is optional - example use of pin d8 as a zone trigger pin for the emulated zone expander  
# this emulates the hardware connection for a pc5108 board. Use a pull down/pull up resistor.  Adjust logic accordingly for the correct logic output. ie invert
 
               
  
text_sensor:
    #general system status online/disconnected 
  - platform: template
    id: system_status
    name: "$systemName System Status"
    icon: "mdi:shield"
    #battery level status for wireless channels, tamper , in alarm, etc for individual zones
  - platform: template
    id: zone_status
    name: "$systemName Zone Status "
    icon: "mdi:shield"  
    # partition status ie read/unavailable, in alarm, etc
  - platform: template
    id: p1
    name: "$systemName Partition 1 Status "
    icon: "mdi:shield"
  #- platform: template
  #  id: p2
  #  name: "$systemName Partition 2 Status " # uncomment to show in home assistant.  
  #  icon: "mdi:shield"  
    # more verbose message regarding the partition status. ie zones open, bypassed, etc

  - platform: template
    id: m1
    name: "$systemName Partition 1 Msg "
    icon: "mdi:alert-box"
  #- platform: template
  #  id: m2
  #  name: "$systemName Partition 2 Msg " # uncomment to show in home assistant
  #  icon: "mdi:alert-box"
   
  - platform: template
    id: line1
    name: "$systemName line1"
    icon: "mdi:alert-box"
  - platform: template
    id: line2
    name: "$systemName line2"
    icon: "mdi:alert-box"  
  #- platform: template
  #  id: line1_2
  #  name: "$systemName line1 partition 2"
  #  icon: "mdi:alert-box"
  #- platform: template
  #  id: line2_2
  #  name: "$systemName line2 partition 2"
  #  icon: "mdi:alert-box" 
    
  - platform: template
    id: event
    name: "$systemName event"
    icon: "mdi:alert-box"  
    
  - platform: template
    id: beeps
    name: "$systemName beeps"
    icon: "mdi:alert-box" 
  #- platform: template
  #  id: beeps_2
  #  name: "$systemName partition 2 beeps"
  #  icon: "mdi:alert-box"   
    
  - platform: template
    id: tr_msg
    name: "$systemName Trouble Msg " # uncomment to show in home assistant
    icon: "mdi:alert-box"
        
switch:
    #shows status of connection status to panel.  You can disconnect before upload using the switch.
  - platform: template
    name: "$systemName Connection"
    id: connection_status_switch
    lambda: |-
      return dsc.keybusConnected;
    icon: "mdi:shield-link-variant"
    turn_on_action:
      - switch.toggle: restart_switch
    turn_off_action:
      - lambda: |-
          disconnectKeybus();
  - platform: restart
    id: restart_switch


I talked with the guy who made the script and found an api call that I can use to set zones.

So it is a binary sensor, would have been easy to say so wouldn’t it.

It should create a binary sensor in HA which mirrors the binary sensor in esphome.

If you have found a solution, please share.

It’s almost like I freely admitted that I didn’t know what I was doing and kept asking for help, weird. And yes I know it created a binary sensor in HA which mirrored the binary sensor in esphome, as I continually said I was trying to figure out how to set any entity in HA. Of course that ended up being the wrong track, but that’s all I was asking for help with.

The solution was to use an api call that it automatically created when you’re using his interface. So instead of trying to set it directly, I needed to have the automation call a service set_zone_fault, which would handle everything for me.

And how would you expect anyone to give you that solution without seeing the code?